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