public IHttpActionResult PutComment(int id, Comment comment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != comment.ID) { return BadRequest(); } db.Entry(comment).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostComment(Comment comment) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Comments.Add(comment); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = comment.ID }, comment); }