Example #1
0
        public ActionResult CreateComment(CreateCommentTicketViewModel formData)
        {
            if (!ModelState.IsValid)
            {
                return(View(formData));
            }

            if (formData is null)
            {
                return(RedirectToDashError());
            }

            var ticket = DbContext.Tickets.FirstOrDefault(tckt => tckt.Id == formData.TicketId);

            if (ticket is null)
            {
                return(RedirectToDashError());
            }

            if (TicketHelper.UserCanAccessTicket(User, ticket))
            {
                ticket.Comments.Add(new Comment
                {
                    UserId      = User.Identity.GetUserId(),
                    DateCreated = DateTime.Now,
                    CommentData = formData.Comment,
                });

                // Notify users of a comment
                TicketHelper.SendNotificationsToUsers(ticket, "comment");

                DbContext.SaveChanges();

                return(RedirectToAction("DetailsTicket", "Ticket", new { ticketId = ticket.Id }));
            }
            else
            {
                return(RedirectToDashError());
            }
        }
Example #2
0
        public ActionResult CreateComment(int?ticketId)
        {
            var ticket = DbContext.Tickets.FirstOrDefault(tckt => tckt.Id == ticketId);

            if (ticket is null)
            {
                return(RedirectToDashError());
            }

            // Do user validation
            if (TicketHelper.UserCanAccessTicket(User, ticket))
            {
                var comment = new CreateCommentTicketViewModel()
                {
                    TicketId = (int)ticketId
                };

                return(View(comment));
            }
            else
            {
                return(RedirectToDashError());
            }
        }