public ActionResult Thread(int page, ManageMessageId?message) { var UserId = User.Identity.GetUserId(); var loggedUserByUserId = _applicationDbContext.Users.SingleOrDefault(i => i.Id == UserId); if (loggedUserByUserId.Career == "General") { ViewBag.StatusMessage = message == ManageMessageId.Error ? "You must enter a comment." : ""; CommentForReportViewModel commentModel = new CommentForReportViewModel(); HtmlToText convert = new HtmlToText(); var reportById = _applicationDbContext.Reports.Where(m => m.ReportId == page).SingleOrDefault(); commentModel.ReportId = reportById.ReportId; commentModel.ReportText = convert.Convert(reportById.ReportText); return(View(commentModel)); } else { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return(RedirectToAction("Login", "Account")); } }
public async Task <ActionResult> CreateThread([Bind(Include = "ThreadId,ReportId,UserId,ThreadText,DateCreated")] CommentForReportViewModel comment) { System.Threading.Thread.Sleep(1000); HtmlToText convert = new HtmlToText(); ManageMessageId?message; Thread thread = new Thread(); var reportById = _applicationDbContext.Reports.Where(m => m.ReportId == comment.ReportId).SingleOrDefault(); string RandomId = Guid.NewGuid().ToString(); string PageTitle = reportById.CompanyorIndividual + " : " + convert.Convert(reportById.ReportText).Substring(0, 50); string sm_PageTitle = Regex.Replace(PageTitle, "[^A-Za-z0-9]", "-"); thread.ReportId = comment.ReportId; thread.ThreadText = comment.ThreadText; thread.UserId = User.Identity.GetUserId(); thread.DateCreated = DateTime.UtcNow; if (comment.ThreadText != null) { if (ModelState.IsValid) { _applicationDbContext.Threads.Add(thread); await _applicationDbContext.SaveChangesAsync(); } } else { message = ManageMessageId.Error; return(RedirectToAction("Thread", new { Controller = "Report", action = "Thread", title = sm_PageTitle, page = thread.ReportId, id = RandomId, message })); } return(RedirectToAction("ReportDetails", new { Controller = "Report", action = "ReportDetails", title = sm_PageTitle, page = thread.ReportId, id = RandomId })); }