Skip to content

Instantly share code, notes, and snippets.

@glennblock
Created May 24, 2012 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennblock/2780448 to your computer and use it in GitHub Desktop.
Save glennblock/2780448 to your computer and use it in GitHub Desktop.
public class CustomerController : ApiController {
private ICustomerContext repo;
public CustomerController(ICustomerContext repo) {
this.repo = repo;
}
public HttpResponseMessage Post(Customer customer) {
repo.Add(customer);
repo.SaveChanges();
var response = Request.CreateResponse(HttpStatusCode.Created, customer);
response.Headers.Location = new Uri(Request.RequestUri, string.format("customer/{0}", customer.id));
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment