using System; using Neo.Afx.Mvc; using System.Web.Mvc; using Neo.LegitimateLicences.Data.Models; using System.Linq; using Neo.Afx.Services.Workflows.Entities; using Neo.LegitimateLicences.Common; using Neo.Afx.Security; using System.Configuration; using Neo.Afx.Services.Workflows; using Neo.Afx.Services.Documents; using Neo.Afx.Services.Documents.Entities; using System.Collections.Generic; using Neo.LegitimateLicences.ApplicationRequest.Models.Database; using System.Reflection; namespace Neo.LegitimateLicences.VerificationConsole { public partial class VerificationConsoleController : Neo.LegitimateLicences.Common.ControllerBase { #region DocumentVerification public ActionResult DocumentVerification(long entityID, long itemID, long documentID, long workflowInstanceTaskID, long dataEntityID, long dataItemID) { #region Data var documentDatabase = new DocumentsDatabase(); var db = new LegitimateDatabase(); var ardDatabase = new ApplicationDatabase(); var document = documentDatabase.GetDocumentObjectWithoutBlob(documentID); var documentChecks = documentDatabase.GetDocumentQuestions(documentID, Profile.UserID); var documentTitle = document.DocumentType.Description; #endregion #region Update question placeholders switch (dataEntityID) { case (short)EntityEnum.ApplicationRequestDetails: var appDetail = db.GetApplicationDetail_ViewOnly(itemID); documentChecks = GetDocumentQuestions(documentChecks, appDetail); break; case (short)EntityEnum.ApplicationLicences: var applicationLicences = ardDatabase.GetApplicationLicencesView(dataItemID, Profile.UserID); documentChecks = GetDocumentQuestions(documentChecks, applicationLicences); break; case (short)EntityEnum.ApplicationLicenceVehicleDetails: var applicationLicenceVehicle = ardDatabase.GetApplicationLicenceVehicleDetailsView(dataItemID, Profile.UserID); documentChecks = GetDocumentQuestions(documentChecks, applicationLicenceVehicle); break; default: break; } #endregion var model = new DocumentVerificationModel() { UserID = Profile.UserID, UserRoles = Profile.Roles, ItemID = itemID, DocumentTypeID = document.DocumentTypeID, DocumentStoreLocationID = _documentStoreLocationID, DocumentName = documentTitle, DocumentChecks = documentChecks, DocumentID = documentID, WorkflowInstanceTaskID = workflowInstanceTaskID }; return View("DocumentVerification", model); } #endregion #region SaveDocumentChecks [HttpPost] public JsonResult SaveDocumentChecks(long entityID, long itemID, long workflowInstanceTaskID, List documentQuestions, string comments) { var database = new LegitimateDatabase(); var documentDatabase = new DocumentsDatabase(); var errorMessage = ""; var success = false; var at = WorkflowHelper.GetActiveTask(entityID, itemID); if (at.WorkflowInstanceTaskID == workflowInstanceTaskID) { documentDatabase.UpdateDocumentQuestions(documentQuestions, Profile.UserID); success = true; } else { success = false; errorMessage = "The given task is not active any more."; } var results = new { Success = success, ErrorMessage = errorMessage }; return Json(results, JsonSerializerOptions.None); } #endregion #region GetDocumentQuestions public List GetDocumentQuestions(List documentChecks, dynamic data) { foreach (var q in documentChecks) { foreach (PropertyInfo prop in data.GetType().GetProperties()) { var name = "$" + prop.Name.ToLower() + "$"; var temp = prop.GetValue(data, null); string value = "N/A"; if (temp != null) { value = prop.GetValue(data, null).ToString(); } q.Question = q.Question.Replace(name, value); } q.Question = q.Question.Replace("\n", ","); } return documentChecks; } #endregion } }