// POST api/ContactDetail public HttpResponseMessage PostContactDetail(ContactDetail contactdetail) { if (ModelState.IsValid) { db.ContactDetails.Add(contactdetail); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, contactdetail); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = contactdetail.ContactDetailId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/ContactDetail/5 public HttpResponseMessage PutContactDetail(Guid id, ContactDetail contactdetail) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != contactdetail.ContactDetailId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(contactdetail).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }