Skip to content

Commit 3aa2a2a

Browse files
committed
Simplify the contacts sample.
1 parent f33b824 commit 3aa2a2a

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

samples/ContactManager.APIs/ContactsController.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ public HttpResponseMessage Get(int id, HttpRequestMessage request)
4242
throw new HttpResponseException(response);
4343
}
4444

45-
var result = new DefaultContentNegotiator().Negotiate(contact.GetType(), request, GlobalConfiguration.Configuration.Formatters);
46-
var contactResponse = new HttpResponseMessage
47-
{
48-
Content = new ObjectContent<Contact>(contact, result.Formatter, result.MediaType.MediaType)
49-
};
45+
var contactResponse = request.CreateResponse(HttpStatusCode.OK, contact);
5046

5147
contactResponse.Content.Headers.Expires = new DateTimeOffset(DateTime.Now.AddSeconds(300));
5248

@@ -56,12 +52,8 @@ public HttpResponseMessage Get(int id, HttpRequestMessage request)
5652
public HttpResponseMessage Post(Contact contact)
5753
{
5854
repository.Post(contact);
59-
60-
var result = new DefaultContentNegotiator().Negotiate(contact.GetType(), Request, GlobalConfiguration.Configuration.Formatters);
61-
var response = new HttpResponseMessage(HttpStatusCode.Created)
62-
{
63-
Content = new ObjectContent<Contact>(contact, result.Formatter, result.MediaType.MediaType)
64-
};
55+
56+
var response = Request.CreateResponse(HttpStatusCode.Created, contact);
6557

6658
response.Headers.Location = new Uri(ControllerContext.Request.RequestUri.LocalPath + "/" + contact.Id.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
6759

0 commit comments

Comments
 (0)