using System; using System.Web.Mvc; using System.Collections.Generic; using Neo.Afx.Mvc; using Neo.Afx.ViewModels; using Neo.Afx.ComponentModel; using Neo.Afx.Services.Workflows; using Neo.Afx.Services.Workflows.Entities; using Neo.LegitimateLicences.Common; using Neo.LegitimateLicences.MDApprovalRequest.Models; using Neo.LegitimateLicences.MDApprovalRequest.Models.Database; using Neo.Afx.Security; using Neo.LegitimateLicences.Common.Helpers; using System.Linq; namespace Neo.LegitimateLicences.MDApprovalRequest { public partial class MDApprovalRequestController { #region Form public ActionResult Form() { var isNew = WebHelper.ItemID == -1; var itemId = WebHelper.ItemID; var taskId = WebHelper.TaskID; var db = new MDApprovalRequestDatabase(); //don't use database as we need the values refreshed every time var mdApprovalDetails = db.GetMDApprovalRequestView(itemId); var mdEntityName = mdApprovalDetails.EntityName.ToString(); var mdRequestAction = mdApprovalDetails.RequestAction != null ? mdApprovalDetails.RequestAction.ToString().ToUpper() : ""; var json = mdApprovalDetails.JSONData != null ? mdApprovalDetails.JSONData.ToString() : ""; json = json.Replace("\\n", "
"); var mdApprovalObjects = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); var model = new MDApprovalRequestFormModel() { UserSecurables = (Profile.Securables != null) ? Profile.Securables.ToList() : new List(), Ui = new Afx.ViewModels.WorkflowConsoleUIProperties(), ChangeData = mdApprovalObjects, EntityName = mdEntityName, RequestAction = mdRequestAction }; model.WorkflowInstance = WorkflowHelper.GetWorkflowInstanceView(WebHelper.EntityID, WebHelper.ItemID, Profile.UserID); #region Get active user task Vw_WorkflowInstanceTask activeUserTask = null; if (taskId != -1) { activeUserTask = WorkflowHelper.GetActiveUserUserTaskByID((long)EntityEnum.LicenceIssueDetails, itemId, taskId, Profile.UserID); } if (activeUserTask == null) { activeUserTask = WorkflowHelper.GetActiveUserTask(Profile.UserID, EntityEnum.LicenceIssueDetails, itemId); } #endregion model.Ui.canSave = (activeUserTask != null && activeUserTask.WorkflowTemplateStepNumber == 2); model.Ui.canRequestCorrection = false; model.Ui.canViewDocuments = false; model.Ui.canDelete = false; var formData = db.GetMDApprovalRequest((long)EntityEnum.MDApprovalRequestDetails, itemId, Profile.UserID); if (formData == null) { throw new Exception("Error initialising object data"); } #region formData.JSONData = formData.JSONData.Replace("\\n", "
"); #endregion model.Data = formData; return View("Form", model); } #endregion } }