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