using System.Web.Mvc; using Neo.Legitimate.Applications.Models; using Neo.Legitimate.Data.Models; using Pilotfish.Afx.Mvc; using Neo.Legitimate.Common; using System; using System.Linq; using Neo.Legitimate.Data.Models.Ltps; namespace Neo.Legitimate.Applications.Controllers { public partial class ApplicationsController : Neo.Legitimate.Common.ControllerBase { #region Action Results #region PurificationBlockedLicences public ActionResult PurificationLtpsPermits() { if (!SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), Securable.ApplicationsModule_Purification_AddToLTPSLicenceList)) { return RedirectToAction("Default", "Applications"); } var database = new LegitimateDatabase(); var ltpsDatabase = new LtpsDatabase(); var model = new PurificationLtpsPermitsModel() { LtpsPermits = ltpsDatabase.ManuallyAddedLtpsPermits() }; ViewBag.Controller = "Applications"; ViewBag.Page = "PurificationLtpsPermits"; return View("PurificationLtpsPermits", model); } #endregion #endregion #region JSON endpoints [HttpPost] public JsonResult InsertLtpsPermit(string applicationNumber, string applicationDate, string applicationType, string receiptNumber, string iDNumber, string firstName, string lastName, string initials, string permitNumber, string startDate, string endDate) { var errorMessage = ""; var success = false; var database = new LegitimateDatabase(); var ltpsDatabase = new LtpsDatabase(); try { if (SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), Securable.ApplicationsModule_Purification_AddToLTPSLicenceList)) { DateTime testDate; if (!DateTime.TryParse(applicationDate, out testDate)) { throw new Exception("Invalid application date"); } if (!DateTime.TryParse(startDate, out testDate)) { throw new Exception("Invalid start date"); } if (!DateTime.TryParse(endDate, out testDate)) { throw new Exception("Invalid end date"); } long applicationNumberResult; if (!long.TryParse(applicationNumber, out applicationNumberResult)) { throw new Exception("Invalid application number. The number must be numeric."); } long receiptNumberResult; if (!long.TryParse(receiptNumber, out receiptNumberResult)) { throw new Exception("Invalid receipt number. The number must be numeric."); } ltpsDatabase.InsertLtpsPermit(applicationNumber, applicationDate, applicationType, receiptNumber, iDNumber, firstName, lastName, initials, permitNumber, startDate, endDate, Profile.UserID); success = true; } else { errorMessage = "Security error"; } } catch (Exception ex) { errorMessage = database.GetInnermostMessage(ex); } var results = new { Success = success, ErrorMessage = errorMessage }; return Json(results, JsonSerializerOptions.None); } #endregion } }