Beispiel #1
0
        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());
            }
        }
Beispiel #2
0
        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 }));
        }
Beispiel #3
0
        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());
            }
        }
Beispiel #4
0
        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));
        }