Created
February 22, 2012 21:37
-
-
Save motowilliams/1887545 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
using ContactManager.Models; | |
namespace ContactManager.Controllers | |
{ | |
public class ContactsController : ApiController | |
{ | |
private readonly IContactRepository repository; | |
public ContactsController(IContactRepository repository) | |
{ | |
this.repository = repository; | |
} | |
public IQueryable<Contact> Get() | |
{ | |
return this.repository.GetAll().AsQueryable(); | |
} | |
public HttpResponseMessage<Contact> Post(Contact contact) | |
{ | |
var post = this.repository.Post(contact); | |
var response = new HttpResponseMessage<Contact>(contact) { StatusCode = HttpStatusCode.Created }; | |
string uri = Url.Route(null, new { id = post.ContactId, controller = "Contact" }); | |
response.Headers.Location = new Uri(Request.RequestUri, uri); | |
return response; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment