// PUT api/Bookmarks/5 public HttpResponseMessage PutBookmark(Int32 id, Bookmark bookmark) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != bookmark.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(bookmark).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Bookmarks public HttpResponseMessage PostBookmark(Bookmark bookmark) { if (ModelState.IsValid) { db.Bookmarks.Add(bookmark); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, bookmark); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = bookmark.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }