public void EditComments(TicketDetailsBindingModel input) { foreach ((Guid key, string content) in input.EditComments) { var comment = _context.Comments.Find(key); Debug.Assert(comment != null); comment.Content = content; } }
public async Task AddCommentThread(Ticket ticket, TicketDetailsBindingModel input, HttpContext request) { ticket.CommentThreads.Add(new CommentThread() { Content = input.NewCommentThreadContent, Parent = ticket, Creator = await _userManager.GetUserAsync(request.User) }); }
public async Task AddComments(TicketDetailsBindingModel input, HttpContext request) { // Want to avoid adding empty comments, since all comments are POSted. foreach (var(replyToThreadId, content) in input.NewComments.Where(r => r.Value != null)) { var commentThread = _context.CommentThreads.Find(replyToThreadId); commentThread.Comments.Add(new Comment { Content = content, Parent = commentThread, Creator = await _userManager.GetUserAsync(request.User) }); } }
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 })); }