public bool UpdateComment(EditAComment model) { using (var ctx = new ApplicationDbContext()) { var commentToUpdate = ctx .Comments .Single(e => e.CommentId == model.CommentId && e.UserId == _userId); commentToUpdate.CommentText = model.CommentText; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(EditAComment commentToEdit) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateCommentService(); if (!service.UpdateComment(commentToEdit)) { return(InternalServerError()); } return(Ok()); }