using Neo.Afx.Services.Workflows; using Neo.LegitimateLicences.Common; using Neo.LegitimateLicences.Common.Helpers; using Neo.LegitimateLicences.Data.Models; using Neo.Afx.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Neo.Afx.Admin.Security; using System.Dynamic; using Neo.Afx.ViewModels; using Neo.Afx.Services.Integration; namespace Neo.LegitimateLicences.Applications { public partial class ApplicationsController : Neo.LegitimateLicences.Common.ControllerBase { #region Action Results #region UnassignedReceipts public ActionResult UnassignedReceipts() { if (!SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), SecurableEnum.ApplicationsModule_Receipts)) { return RedirectToAction("Default", "Applications"); } var database = new LegitimateDatabase(); var model = new UnassignedReceiptsModel { UnassignedReceipts = database.GetUnassignedReceipts(Profile.UserID), Lookups = GetLookups() }; WebHelper.SetLastPageVisited(HttpContext, "Applications/UnassignedReceipts"); ViewBag.Controller = "Applications"; ViewBag.Page = "UnassignedReceipts"; return View("Payment.UnassignedReceipts", model); } public ActionResult CreateUnassignedReceipt() { if (!SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), SecurableEnum.ApplicationsModule_Receipts_Createreceipt)) { return RedirectToAction("Default", "Applications"); } var model = new UnassignedReceiptsModel { Lookups = GetLookups() }; return View("Payment.CreateUnassignedReceipt", model); } #endregion #endregion #region JSON endpoints #region CreateUnassignedReceipt [HttpPost] public JsonResult CreateUnassignedReceipt(long applicationRequestTypeID, long paymentTypeID, string applicantName, string idNumber, string olPermitNumber, string vehicleRegistrationNumber, string chassisNumber) { if (!SecurityHelper.UserHasAccessToSecurable(Profile.Securables.ToList(), SecurableEnum.ApplicationsModule_Receipts_Createreceipt)) { throw new Exception("Security error"); } var database = new LegitimateDatabase(); ReceiptDetail receiptDetail = null; var errorMessage = ""; var success = false; try { receiptDetail = database.CreateUnassignedReceipt(applicationRequestTypeID, paymentTypeID, applicantName, idNumber, olPermitNumber, vehicleRegistrationNumber, chassisNumber, Profile.UserID); success = true; } catch (Exception ex) { errorMessage = ex.Message; } var results = new { Receipt = receiptDetail, Success = success, ErrorMessage = errorMessage }; return Json(results, JsonSerializerOptions.None); } #endregion #endregion #region GetLookups public List GetLookups() { var lookups = new List(); var database = new LegitimateDatabase(); var integrationStore = new SqlIntegrationStore(); try { integrationStore.Open(); lookups.Add(new LookupList("ApplicationRequestTypes", integrationStore.GetDataEntities("ApplicationRequestTypes", string.Empty))); lookups.Add(new LookupList("PaymentTypes", integrationStore.GetDataEntities("PaymentTypes", string.Empty))); } finally { integrationStore.Close(); } return lookups; } #endregion } }