public ActionResult EditComment(EditCommentTicketViewModel formData) { if (!ModelState.IsValid) { return(View(formData)); } if (formData is null) { return(RedirectToDashError()); } var comment = DbContext.Comments.FirstOrDefault(cmt => cmt.Id == formData.Id); if (comment is null) { return(RedirectToDashError()); } if (TicketHelper.UserCanAccessComment(User, comment)) { comment.CommentData = formData.Comment; DbContext.SaveChanges(); return(RedirectToAction("DetailsTicket", "Ticket", new { ticketId = formData.TicketId })); } else { return(RedirectToDashError()); } }
public ActionResult EditComment(int id, EditCommentTicketViewModel formData) { if (!ModelState.IsValid) { var comment = AppHepler.GetTicketCommentById(id); var model = new EditCommentTicketViewModel(); model.Comment = comment.Comment; model.TicketId = comment.TicketId; return(View(model)); } var commentForSaving = AppHepler.GetTicketCommentById(id); commentForSaving.Comment = formData.Comment; if (commentForSaving == null) { return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed)); } DbContext.SaveChanges(); return(RedirectToAction(nameof(TicketController.Detail), new { id = commentForSaving.TicketId })); }
public ActionResult EditComment(int?commentId) { // Get comment being edited var comment = DbContext.Comments.FirstOrDefault(cmt => cmt.Id == commentId); if (comment is null) { return(RedirectToDashError()); } // Do user validation if (TicketHelper.UserCanAccessComment(User, comment)) { var commentViewModel = new EditCommentTicketViewModel() { Id = comment.Id, TicketId = comment.TicketId, Comment = comment.CommentData, }; return(View(commentViewModel)); } else { return(RedirectToDashError()); } }
public ActionResult EditComment(int?id) { if (!id.HasValue) { return(RedirectToAction(nameof(TicketController.Index))); } var comment = AppHepler.GetTicketCommentById(id); if (comment == null) { return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed)); } var model = new EditCommentTicketViewModel(); model.Comment = comment.Comment; model.TicketId = comment.TicketId; return(View(model)); }