Пример #1
0
        public async Task <IActionResult> Details(Guid id, TicketDetailsBindingModel input, string task)
        {
            var ticket = _ticketService.GetTicket(id);

            if (ticket == null)
            {
                return(View("Error404"));
            }

            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                var viewModel = _ticketService.DetailsTicketViewModel(ticket, allErrors);
                return(View(viewModel));
            }

            if (task == "create")
            {
                if (input.NewCommentThreadContent != null)
                {
                    await _commentService.AddCommentThread(ticket, input, HttpContext);
                }
                if (input.NewComments != null)
                {
                    await _commentService.AddComments(input, HttpContext);
                }
            }
            else
            {
                if (input.EditCommentThreads != null)
                {
                    _commentService.EditCommentThread(input);
                }

                if (input.EditComments != null)
                {
                    _commentService.EditComments(input);
                }
            }

            ticket.UpdatedDate = DateTime.Now;
            _context.SaveChanges(true);

            return(RedirectToAction("Details", new { id }));
        }