// GET: Report public ActionResult Index() { ReportDAL dal = new ReportDAL(_db); string userId = User.Identity.GetUserId(); if (dal.UserHasIncompleteReport(userId)) return RedirectToAction("Complete", new { uncompletedExists = true, redirected=true }); return RedirectToAction("Startup", "Report"); }
public ActionResult Startup(bool reportCompleted = false, int? associatedProjectId = null) { Project associatedProject = null; if (reportCompleted) ViewBag.AppMessage = new AppMessage() { Type = AppMessage.Success, Message = AppString.ReportCompleted }; if (associatedProjectId != null) { associatedProject = _db.Projects.Single(p => p.Id == associatedProjectId); ViewBag.AppMessage = new AppMessage() { Type = AppMessage.Success, Message = String.Format(AppString.ProjectAssociated, associatedProject.Name) }; } string userId = User.Identity.GetUserId(); ErrorLogger.LogString(User.IsInRole("Admin").ToString()); // Makes sure that users finish previous reports first. ReportDAL rDb = new ReportDAL(_db); if (rDb.UserHasIncompleteReport(userId)) return RedirectToAction("Index"); ReportStartupViewModel model = new ReportStartupViewModel(); try { PrepareProjectsForViewModel(model, associatedProject); } catch (Exception e) { // User is not logged in properly. Maybe a threading issue? (This code is a workaround) ErrorLogger.LogString("Could not log in. userId = " + User.Identity.GetUserId() ); return RedirectToAction("Index", "Report"); } // A user must have atleast one associated project to be able to report. Values are set in the PrepareProjectForStartup method call. if (model.AvailableProjects == null && model.SelectedProjectName == null) return RedirectToAction("Associate", "Project"); PrepareCarsForViewModel(model); return View(model); }