// POST api/Detail public HttpResponseMessage PostDetail(Detail detail) { if (ModelState.IsValid) { db.Details.Add(detail); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, detail); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = detail.DetailId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/Detail/5 public HttpResponseMessage PutDetail(int id, Detail detail) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != detail.DetailId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(detail).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }