using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Neo.Legitimate.BulkVehicleVerificationConsole.Models; using Neo.Legitimate.Data.Models; using Pilotfish.Afx.Mvc; using Pilotfish.Afx.Services.Forms; using Pilotfish.Afx.Services.Forms.Entities; using Pilotfish.Afx.Services.Workflows; using Neo.Legitimate.Common; using System; using System.Configuration; using Neo.Legitimate.Data; using Pilotfish.Afx.Services.Comments; using Microsoft.AspNet.SignalR.Infrastructure; using Pilotfish.Afx.Security; using Pilotfish.Afx.Services.Workflows.Entities; using Pilotfish.Afx.Services.Comments.Entities; namespace Neo.Legitimate.BulkVehicleVerificationConsole.Controllers { [Authorize] public partial class BulkVehicleVerificationConsoleController : Neo.Legitimate.Common.ControllerBase { private const long _documentStoreLocationID = 3; #region Action Results #region Default public ActionResult Default(long applicationRequestDetailID, long workflowInstanceTaskID) { var database = new LegitimateDatabase(); var commentDatabase = new CommentsDatabase(); var formDatabase = new FormsDatabase(); var workflowsDatabase = new WorkflowsDatabase(); var application = database.GetApplicationRequestDetail_ViewOnly(applicationRequestDetailID); var vehicles = database.GetApplicationVehicleDetailsInBulk(applicationRequestDetailID, Profile.UserID); var licence = new Vw_LicenceIssueDetails(); var canAction = false; #region ensure that task is assigned to current user var at = WorkflowHelper.GetActiveTask((long)Entity.ApplicationRequestDetails, applicationRequestDetailID); if (at == null) { return RedirectToAction("ShowError", "Error", new { msg = "No outstanding task found for the application" }); } if (at.WorkflowTemplateStepID != 8 /*Bulk vehicle verification*/) { return RedirectToAction("ShowError", "Error", new { msg = "The application is not in verification any more" }); } if (!SecurityHelper.UserHasRole(((UserProfile)Profile).Roles, Neo.Legitimate.Common.Role.Verifier)) { return RedirectToAction("ShowError", "Error", new { msg = "The user has not been linked to the verification role" }); } if (at.AssignedToID == (long)Defaults.SystemUserID) { var user = ConfigurationManager.AppSettings["SystemUsername"].ToString(); var reassign = workflowsDatabase.ReAssignWorkflowInstanceTask(at.WorkflowInstanceTaskID, Profile.UserID, "", user); if (String.IsNullOrEmpty(reassign)) { workflowInstanceTaskID = WorkflowHelper.GetActiveTask((long)Entity.ApplicationRequestDetails, applicationRequestDetailID).WorkflowInstanceTaskID; canAction = true; } else { return RedirectToAction("ShowError", "Error", new { msg = "Error re-assiging verification task: " + reassign }); } } else if (at.AssignedToID == Profile.UserID) { workflowInstanceTaskID = at.WorkflowInstanceTaskID; canAction = true; } else if (workflowsDatabase.IsWorkflowBuddy(at.WorkflowID, at.AssignedToID, Profile.UserID)) { workflowInstanceTaskID = at.WorkflowInstanceTaskID; canAction = true; } else { canAction = false; } #endregion var model = new DefaultModel { Application = application, CanAction = canAction, WorkflowInstanceTaskID = workflowInstanceTaskID, Vehicles = new List() }; foreach (var vehicle in vehicles.Where(a => !a.IsVerified)) { var vehicleQuestions = new List>(); #region COR Questions if (vehicle.CorDocID.HasValue) { vehicleQuestions.Add(new KeyValuePair(vehicle.CorDocID.Value, "Is the licence number on the COR " + vehicle.VehicleRegistrationNumber + "")); vehicleQuestions.Add(new KeyValuePair(vehicle.CorDocID.Value, "Is the VIN number on the COR " + vehicle.VIN + "")); vehicleQuestions.Add(new KeyValuePair(vehicle.CorDocID.Value, "Is the engine number on the COR " + vehicle.EngineNumber + "")); vehicleQuestions.Add(new KeyValuePair(vehicle.CorDocID.Value, "Is the COR a certified copy?")); } #endregion #region Logbook Questions if (vehicle.LogbookDocID.HasValue) { vehicleQuestions.Add(new KeyValuePair(vehicle.LogbookDocID.Value, "Is the VIN number on the logbook " + vehicle.VIN + "")); vehicleQuestions.Add(new KeyValuePair(vehicle.LogbookDocID.Value, "Is the logbook a certified copy?")); } #endregion #region PrDP Questions if (vehicle.PdpDocID.HasValue) { vehicleQuestions.Add(new KeyValuePair(vehicle.PdpDocID.Value, "Is the PrDp a Certified and Valid Copy?")); } #endregion model.Vehicles.Add(new VerifiableBulkVehicle() { Vehicle = vehicle, Questions = vehicleQuestions }); } ViewBag.Controller = "Bulk Vehicle Verification Details"; ViewBag.Page = "Bulk Vehicle Verification Details"; return View("Default", model); } #endregion #endregion #region JSON endpoints #region CompleteApplicationVerification [HttpPost] public JsonResult SaveVehicleDetailsInBulkVerification(long applicationVehicleDetailsInBulkID, long applicationRequestDetailID, string exceptionDetails, bool isLastVehicleToBeVerified) { var database = new LegitimateDatabase(); var errorMessage = ""; var success = false; try { database.SaveVehicleDetailsInBulkVerification(applicationVehicleDetailsInBulkID, applicationRequestDetailID, string.IsNullOrEmpty(exceptionDetails), !string.IsNullOrEmpty(exceptionDetails), exceptionDetails, isLastVehicleToBeVerified, Profile.UserID); success = true; } catch (Exception ex) { errorMessage = database.GetInnermostMessage(ex); } var results = new { Success = success, ErrorMessage = errorMessage }; return Json(results, JsonSerializerOptions.None); } #endregion #endregion } }