public HttpResponseMessage Put(int id, ContactBO contact) { contact.Id = id; var entity = ContactsMap.Map(contact); if(!Contactrepository.Update(entity)) { throw new HttpResponseException(HttpStatusCode.NotModified); } else { return new HttpResponseMessage(HttpStatusCode.OK); } }
public static Contact Map(ContactBO entityBO) { return Mapper.Map<ContactBO, Contact>(entityBO); }
public HttpResponseMessage Post(ContactBO request) { var data = ContactsMap.Map(request); var entity = Contactrepository.Insert(data); var response = Request.CreateResponse(HttpStatusCode.Created, entity); try { string uri = Url.Link("DefaultApi", new { id = entity.ID }); response.Headers.Location = new Uri(uri); } catch (Exception e) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An error occurred, please try again"), ReasonPhrase = "Critical exception" }); } return response; }