public IHttpActionResult UpdateReply([FromUri] int id, [FromBody] ReplyUpdate reply) { var service = CreateReplyService(); if (service.UpdateReply(id, reply)) { return(Ok("Reply Updated")); } return(InternalServerError()); }
public bool UpdateReply(ReplyUpdate model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Replies.Single(e => e.Id == model.Id); entity.Text = model.Text; return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Put(ReplyUpdate reply) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateReplyService(); if (!service.UpdateReply(reply)) { return(InternalServerError()); } return(Ok()); }
// Put -- Update Reply by Id public bool UpdateReply(int id, ReplyUpdate reply) { using (var ctx = new ApplicationDbContext()) { var entity = ctx.Replies.Single(e => e.Id == id); //Make sure only original commenter can update comment if (entity.CommenterId != _userId) { return(false); } entity.Text = reply.CommentText; return(ctx.SaveChanges() == 1); } }