using Neo.Afx.Security; using Neo.LegitimateLicences.ApplicationRequest.Models.Database; using Neo.LegitimateLicences.Common; using Neo.LegitimateLicences.Common.Helpers; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace Neo.LegitimateLicences.ApplicationRequest { public partial class ApplicationRequestController { #region Dashboard /// /// Returns Application Request View /// /// public ActionResult Dashboard() { var isNew = WebHelper.ItemID == -1; var itemId = WebHelper.ItemID; var model = new ApplicationRequestDashboardModel { UserSecurables = (Profile.Securables != null) ? Profile.Securables.ToList() : new List(), ApplicationStatusSummary = new List() }; if (!isNew) { var applicationDatabase = new ApplicationDatabase(); model.CanAddTags = SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), SecurableEnum.ApplicationsModule_ApplicationRequest_AddTag); model.ApplicationView = applicationDatabase.GetApplicationView(itemId, Profile.UserID); model.ApplicationStatusSummary = applicationDatabase.GetApplicationWorkflowStatusSummary(itemId, Profile.UserID); model.WorkflowInstance = WorkflowHelper.GetWorkflowInstanceView(WebHelper.EntityID, WebHelper.ItemID, Profile.UserID); #region Get List of Failed document checks if (model.ApplicationView.ApplicationSubStatusID == (short)ApplicationSubStatusEnum.AwaitingCorrection) { model.ApplicationFailedDocumentChecks = applicationDatabase.GetFailedApplicationDocumentVerifications(itemId, Profile.UserID); } else { model.ApplicationFailedDocumentChecks = new List(); } #endregion var application = applicationDatabase.GetApplicationForm(itemId, Profile.UserID); model.Data = application; #region Determine if application was split from parent application if (application.CopiedFromApplicationDetailID != null) { model.HasParentApplication = true; model.ParentApplicationView = applicationDatabase.GetApplicationView(application.CopiedFromApplicationDetailID.Value, Profile.UserID); } #endregion #region Tags var applicationTags = applicationDatabase.GetApplicationTags(itemId, Profile.UserID); var tagsRequiringReview = new List(); var completedTags = new List(); if (applicationTags.Count > 0) { tagsRequiringReview = applicationTags.Where(a => a.ReviewRequiredByRoleID != null && a.ClearedByID == null).ToList(); completedTags = applicationTags.Where(a => a.ReviewRequiredByRoleID != null && a.ClearedByID != null).ToList(); } if (tagsRequiringReview.Count() != 0) { model.TagsRequiringReview = tagsRequiringReview; model.TagsRequiringReviewIsVisible = true; model.ViewTagsLinkIsVisible = false; if (tagsRequiringReview.Any(tags => Profile.Roles.Any(role => role == tags.ReviewRequiredByRoleID))) { model.ManageTagsIsVisible = true; } } else if (completedTags.Any()) { model.TagsRequiringReviewIsVisible = true; model.ViewTagsLinkIsVisible = true; } model.TagEditorIsVisible = true; model.Tags = applicationTags; #endregion #region Get Latest Comments model.Comments = CommentHelper.GetLatestComments(WebHelper.EntityID, WebHelper.ItemID); #endregion } return View("Dashboard", model); } #endregion } }