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