public ActionResult Edit(long id) { var rlc = new RequestLockManagementController(); var uc = new UserManagementController(); UserProfile up = uc.getUserProfile(User.Identity.Name); RequestLock rl = rlc.getRequestLock(id); if (rl == null) { rlc.addLock(id, up.UserId); } else if (rl.UserID != up.UserId) { // Locked to someone else, redirect return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.AccessingLocked }); } var dc = new DropdownManagementController(); var rmc = new RequestManagementController(); RequestContent reqContent = rmc.getRequestDetails(id); if (reqContent.requestStatus == Constants.RequestStatus.Invalid) { // Invalid request, cannot edit return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.EditingInvalid }); } ViewBag.RequestorTypes = new SelectList( dc.getEntries(Constants.DropdownTable.RequestorType), "id", "text"); ViewBag.Regions = new SelectList( dc.getEntries(Constants.DropdownTable.Region), "id", "text"); ViewBag.GenderOptions = new SelectList(Constants.genderOptions); return View(reqContent); }
public ActionResult Details(long id) { var rmc = new RequestManagementController(); var rlc = new RequestLockManagementController(); var upc = new UserManagementController(); var db = new CAIRSDataContext(); int timeSpent = 0; // Set up the Request Object RequestContent request = rmc.getRequestDetails(id); if (request == null) { ViewBag.Title = Constants.UIString.TitleText.VIEW_REQUEST + " - " + Constants.UIString.TitleText.ERROR; ViewBag.Error = "The Request ID provided does not exist in the database."; return View((object) null); } ViewBag.Title = Constants.UIString.TitleText.VIEW_REQUEST + " - " + Constants.UIString.TitleText.REQUEST_NUM + request.requestID; // Show error if not editor/administrator and request isn't complete if (!User.IsInRole(Constants.Roles.REQUEST_EDITOR) && !User.IsInRole(Constants.Roles.ADMINISTRATOR) && request.requestStatus != Constants.RequestStatus.Completed) { ViewBag.Title = Constants.UIString.TitleText.VIEW_REQUEST + " - " + Constants.UIString.TitleText.ERROR; ViewBag.Error = "You do not have the necessary permissions to view this request."; return View((object) null); } // Show error if not administrator and request is invalid (deleted) if (!User.IsInRole(Constants.Roles.ADMINISTRATOR) && request.requestStatus == Constants.RequestStatus.Invalid) { ViewBag.Title = Constants.UIString.TitleText.VIEW_REQUEST + " - " + Constants.UIString.TitleText.ERROR; ViewBag.Error = "You do not have the necessary permissions to view this request."; return View((object) null); } // Show error if you can't view due to locked status if (rlc.isLocked(id) && !User.IsInRole(Constants.Roles.ADMINISTRATOR)) { // Check if it's not locked to you if (!User.IsInRole(Constants.Roles.REQUEST_EDITOR) || rlc.getRequestLock(id).UserID != upc.getUserProfile(User.Identity.Name).UserId) { request = null; ViewBag.Title = Constants.UIString.TitleText.VIEW_REQUEST + " - " + Constants.UIString.TitleText.ERROR; ViewBag.Error = "This request has been locked to another person and cannot be viewed until unlocked."; return View((object) null); } } // Set up Time Spent (Question-Dependent) foreach (QuestionResponseContent qr in request.questionResponseList) { timeSpent += qr.timeSpent.GetValueOrDefault(0); } ViewBag.TimeSpent = timeSpent; ViewBag.DataContext = new CAIRSDataContext(); // Created By AuditLog auditLog = (from al in db.AuditLogs where (int) al.AuditType == (int) Constants.AuditType.RequestCreation && al.RequestID == request.requestID select al).FirstOrDefault(); if (auditLog != null && auditLog.UserProfile != null) { ViewBag.CreatedBy = auditLog.UserProfile.UserFullName; } else { ViewBag.CreatedBy = ""; } // Closed By auditLog = (from al in db.AuditLogs where (int) al.AuditType == (int) Constants.AuditType.RequestCompletion && al.RequestID == request.requestID select al).FirstOrDefault(); if (auditLog != null && auditLog.UserProfile != null) { ViewBag.CompletedBy = auditLog.UserProfile.UserFullName; } else { ViewBag.CompletedBy = ""; } // add AuditLog entry for viewing var almc = new AuditLogManagementController(); almc.addEntry(id, upc.getUserProfile(User.Identity.Name).UserId, Constants.AuditType.RequestView); ViewBag.IsLocked = rlc.isLocked(id); if (ViewBag.IsLocked) { ViewBag.IsLockedToMe = rlc.getRequestLock(id).UserID == upc.getUserProfile(User.Identity.Name) .UserId; } else { ViewBag.IsLockedToMe = false; } return View(request); }