public IHttpActionResult PutCommentBook(int id, CommentBook commentBook) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != commentBook.CommentID) { return(BadRequest()); } db.Entry(commentBook).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CommentBookExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostCommentBook(CommentBook commentBook) { db.CommentBooks.Add(commentBook); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = commentBook.CommentID }, commentBook)); }
public IHttpActionResult DeleteCommentBook(int id) { CommentBook commentBook = db.CommentBooks.Find(id); if (commentBook == null) { return(NotFound()); } db.CommentBooks.Remove(commentBook); db.SaveChanges(); return(Ok(commentBook)); }