using System.Web.Mvc; using System.Web.UI; using Neo.Afx.Security; using System; using System.Configuration; using System.Web.Profile; using System.Linq; using Neo.LegitimateLicences.Common; using System.Web.Security; using Neo.Afx.Services.Audits; using Neo.LegitimateLicences.Common.ViewModels; using Neo.LegitimateLicences.Common.Helpers; using Neo.Afx.Services.Workflows; using Neo.LegitimateLicences.Web.Models.Afx; using Neo.Afx.Services.Workflows.Entities; namespace Neo.LegitimateLicences.Web.Controllers { public partial class AfxController { #region MyTasks public ActionResult MyTasks() { var vm = new AfxMyTasksModel(); var wd = new WorkflowsDatabase(); vm.MyTasks = wd.GetTasks(Profile.UserID, 1 /*assigned*/); return View("~/Views/Shared/Afx/Tasks/MyTasks.cshtml", vm); } #endregion #region Tasks public ActionResult Tasks() { return View("~/Views/Shared/Afx/Tasks/List.cshtml", GetTasksModel()); } #endregion #region GetTasksModel public AfxTasksModel GetTasksModel() { var itemID = WebHelper.ItemID; var entityID = WebHelper.EntityID; var wd = new WorkflowsDatabase(); var wi = wd.GetWorkflowInstance(entityID, itemID); if (wi == null) { throw new Exception("Workflow instance not found"); } foreach (var t in wi.WorkflowInstanceTasks.Where(a => a.WorkflowInstanceTaskStatusID == 1 && a.AssignedToID != Profile.UserID)) //1=Outstanding { t.canReAssignToSelf = wd.WorkflowInstanceTaskCanAssignToMe(t.WorkflowInstanceTaskID, Profile.UserID); } var model = new AfxTasksModel() { UserID = Profile.UserID, UserRoles = Profile.Roles, WorkflowInstance = wi, CanReassign = SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), SecurableEnum.AfxWorkflowCanReassign), WorkflowInstanceRoute = wd.GetWorkflowInstanceRoute(wi.WorkflowTemplateID, wi.WorkflowInstanceID, Profile.UserID) }; if (wi != null) { string description = wi.Description; // For App Provider Issue Request (EntityID 1042), append provider name if (entityID == 1042) // AppProviderIssueRequest { var legitimateDb = new Neo.LegitimateLicences.Data.Models.LegitimateDatabase(); var providerName = legitimateDb.Context.Database.SqlQuery( @"SELECT TOP 1 ISNULL(PP.TradingName, PP.LegalName) AS ProviderName FROM App.AppProviderIssueDetails APID INNER JOIN Verified.ProviderCertificates PC ON PC.ProviderCertificateID = APID.VerifiedProviderCertificateID INNER JOIN Verified.PlatformProviders PP ON PP.PlatformProviderID = PC.PlatformProviderID WHERE APID.AppProviderIssueDetailID = @p0", new object[] { itemID }).FirstOrDefault(); if (!string.IsNullOrEmpty(providerName)) { description = description + " " + providerName; } } ViewBag.Title = "Task activity for " + wi.ReferenceNumber + ", " + description; } else { ViewBag.Title = "Task activity"; } return model; } #endregion #region ReassignTask public ActionResult ReassignTask(long entityID, long itemID,long taskID) { return View("~/Views/Shared/Afx/Tasks/ReassignTask.cshtml", GetReassignTaskModel(taskID)); } #endregion #region GetReassignTaskModel public AfxTasksModel GetReassignTaskModel(long taskID) { var itemID = WebHelper.ItemID; var entityID = WebHelper.EntityID; var wd = new WorkflowsDatabase(); var wi = wd.GetWorkflowInstance(entityID, itemID); if (wi == null) { throw new Exception("Workflow instance not found"); } var model = new AfxTasksModel() { UserID = Profile.UserID, UserRoles = Profile.Roles, WorkflowInstance = wi, CanReassign = SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), SecurableEnum.AfxWorkflowCanReassign), WorkflowInstanceRoute = wd.GetWorkflowInstanceRoute(wi.WorkflowTemplateID, wi.WorkflowInstanceID, Profile.UserID) }; model.CurrentTask = wi.WorkflowInstanceTasks.Where(a => (a.WorkflowInstanceTaskID == taskID && a.WorkflowInstanceTaskStatusID == (short)WorkflowInstanceTaskStatusEnum.Outstanding)).FirstOrDefault(); if (wi != null) { ViewBag.Title = "Reassign task for " + wi.ReferenceNumber + ", " + wi.Description; } else { ViewBag.Title = "Reassign task"; } return model; } #endregion } }