public IActionResult PostComment(CommentViewModel commentViewModel) { if (ModelState.IsValid) { _comment.Text = HtmlMarkupManager.EncodeHtml(commentViewModel.Text); _comment.CreatorId = CookieManager.GetUserId(); _comment.TicketId = commentViewModel.TicketId; _commentCollection.Add(_comment); return(RedirectToAction("Details", "Tickets", new { id = Convert.ToInt32(commentViewModel.TicketId) })); } TempData["CommentPostFailed"] = "Please write your comment before posting."; return(RedirectToAction("Details", "Tickets", new { id = Convert.ToInt32(commentViewModel.TicketId) })); }
/*Due to unknown reasons, this Action does not work & due to lack of time I've given up on fixing it.*/ public IActionResult UpdateComment(CommentViewModel commentViewModel) { if (ModelState.IsValid) { _comment.Text = HtmlMarkupManager.EncodeHtml(commentViewModel.Text); _comment.CreatorId = commentViewModel.AuthorId; _comment.TicketId = commentViewModel.TicketId; _comment.CreatedAt = commentViewModel.CreatedAt; _comment.LastEdited = commentViewModel.LastEdited; _comment.Edit(_comment); return(RedirectToAction("Details", "Tickets", new { id = Convert.ToInt32(commentViewModel.TicketId) })); } TempData["CommentEditFailed"] = "Please write your comment before posting."; return(RedirectToAction("Details", "Tickets", new { id = Convert.ToInt32(commentViewModel.TicketId) })); }
public IActionResult CreateTicket(TicketViewModel ticketViewModel) { string strippedContent = HtmlMarkupManager.StripHtmlTags(ticketViewModel.Content); if (ModelState.IsValid && strippedContent.Length < 5000) { ticketViewModel.Content = HtmlMarkupManager.EncodeHtml(ticketViewModel.Content); ITicket ticket = ViewModelConverter.ConvertViewModelToTicket(ticketViewModel); _user.CreateTicket(ticket); } else if (!ModelState.IsValid && strippedContent.Length > 5000) { TempData["CreateTicketFailed"] = "The content of your ticket has more than 5000 characters, please shorten the text."; return(RedirectToAction("Create")); } else { TempData["CreateTicketFailed"] = "Failed to create ticket. Did you fill in every field?"; return(RedirectToAction("Create")); } return(RedirectToAction("Dashboard", "Home")); }
public IActionResult Details(int id) { var ticket = _ticketColl.GetTicketById(id); ViewData["TicketID"] = id; ticket.Content = HtmlMarkupManager.DecodeHtml(ticket.Content); TicketViewModel ticketViewModel = ViewModelConverter.ConvertTicketToViewModel(ticket); ticketViewModel.Author = _userColl.GetUserById(ticketViewModel.AuthorId).FullName; ticketViewModel.Agent = _userColl.GetUserById(ticketViewModel.AgentId).FullName; var comments = _commentColl.GetCommentsByTicketId(ticketViewModel.Id); ticketViewModel.Comments = new List <CommentViewModel>(); if (comments.Count != 0) { foreach (var comment in comments) { CommentViewModel cvm = new CommentViewModel() { Id = comment.Id, TicketId = comment.TicketId, Author = _userColl.GetUserById(comment.CreatorId).FullName, Text = HtmlMarkupManager.DecodeHtml(comment.Text), CreatedAt = comment.CreatedAt, LastEdited = comment.LastEdited }; ticketViewModel.Comments.Add(cvm); } } else { TempData["NoComments"] = "No comments have been found for this ticket!"; } return(View(ticketViewModel)); }
public IActionResult EditTicket(TicketViewModel ticket) { _ticket.Content = HtmlMarkupManager.EncodeHtml(ticket.Content); _ticket.Edit(ViewModelConverter.ConvertViewModelToTicket(ticket)); return(RedirectToAction("Details", new { id = ticket.Id })); }