public void Delete(int id) { ContactBO contact = ContactsMap.Map(this.Contactrepository.GetContactById(id)); if (contact == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Contactrepository.Delete(id); }
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 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); }