using System; using System.Collections.Generic; using System.Linq; using System.Web; using OSS.Repositories; using System.Web.Mvc; using OSS.Models; using System.Security; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using System.Globalization; using System.IO; using System.Threading.Tasks; using Microsoft.Security.Application; using System.Net.Http; using System.Text; using System.Net.Http.Headers; using System.Security.AccessControl; using Rotativa; using System.Data.Entity.Migrations; using System.Web.WebPages; using System.Data.Entity.Validation; using System.Data.SqlClient; namespace OSS.Controllers { [Authorize] public class NewCOIController : Controller { private OSSDBContext myContext = new OSSDBContext(); public ActionResult Index() { return View(); } public ActionResult IndexExpansion() { return View(); } public ActionResult IndexAmendment() { return View(); } public ActionResult AmendmentApplication() { return View("AmendmentApplication"); } public ActionResult Extension() { return View("Extension"); } public ActionResult ExtensionIndex() { return View("ExtensionIndex"); } public ActionResult PickUpOfficeAmendment() { return View("PickUpOfficeAmendment"); } public ActionResult PickUpOfficeNew() { return View("PickUpOfficeNew"); } public ActionResult PickUpOfficeExpansion() { return View("PickUpOfficeExpansion"); } public ActionResult PickUpOfficeExtension() { return View("PickUpOfficeExtension"); } public ActionResult ApplicationStatus(long Id) { var selectData = myContext.ApplicationManagers.Where(t => t.ApplicationID == Id).SingleOrDefault(); Session["CompanyName"] = selectData.CompanyName; Session["ProjectName"] = selectData.ProjectName; Session["ProjectCode"] = selectData.ProjectCode; Session["ApplicationDate"] = selectData.CreatedDate; Session["ApplicationType"] = selectData.ServiceName; Session["EvaluationStatus"] = selectData.EvaluationStatus; Session["Comment"] = selectData.Comments; return View("ApplicationStatus"); } public ActionResult ApplicationStatuAmend(long Id) { var selectData = myContext.ApplicationManagers.Where(t => t.ApplicationID == Id).SingleOrDefault(); Session["CompanyName"] = selectData.CompanyName; Session["ProjectName"] = selectData.ProjectName; Session["ProjectCode"] = selectData.ProjectCode; Session["ApplicationDate"] = selectData.CreatedDate; Session["ApplicationType"] = selectData.ServiceName; Session["EvaluationStatus"] = selectData.EvaluationStatus; Session["Comment"] = selectData.Comments; return View("ApplicationStatuAmend"); } public ActionResult ApplicationStatusComment(long Id) { var selectData = myContext.ApplicationManagers.Where(t => t.ApplicationID == Id).SingleOrDefault(); Session["CompanyName"] = selectData.CompanyName; Session["ProjectName"] = selectData.ProjectName; Session["ProjectCode"] = selectData.ProjectCode; Session["ApplicationDate"] = selectData.CreatedDate; Session["ApplicationType"] = selectData.ServiceName; Session["Comment"] = selectData.Comments; return View("ApplicationStatusComment"); } public ActionResult ApplicationStatusExtension(long Id) { var selectData = myContext.ApplicationManagers.Where(t => t.ApplicationID == Id).SingleOrDefault(); Session["CompanyName"] = selectData.CompanyName; Session["ProjectName"] = selectData.ProjectName; Session["ProjectCode"] = selectData.ProjectCode; Session["ApplicationDate"] = selectData.CreatedDate; Session["ApplicationType"] = selectData.ServiceName; Session["Comment"] = selectData.Comments; return View("ApplicationStatusExtension"); } public ActionResult ValidateAttachments() { // var ProjectCode = Session["ProjectCode"].ToString(); // var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Form"); // if (checkApplicationForm == null) // { // TempData["error"] = " Please upload Application form"; // return RedirectToAction("AttachmentsNew"); // } // var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Bank Statement"); // if (checkAttachmentBank == null) // { // TempData["error"] = " Please upload Bank Statement"; // return RedirectToAction("AttachmentsNew"); // } // var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Board Resolution"); // if (checkAttachmentBoard == null) // { // TempData["error"] = " Please upload Board Resolution"; // return RedirectToAction("AttachmentsNew"); // } // var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Business Plan"); // if (checkAttachmentBusinesP == null) // { // TempData["error"] = " Please upload Business Plan"; // return RedirectToAction("AttachmentsNew"); // } // var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "INCORPORATION"); // if (checkAttachmentInc == null) // { // TempData["error"] = " Please upload Certificate of Incorporation"; // return RedirectToAction("AttachmentsNew"); // } return RedirectToAction("PickUpOfficeNew"); } public ActionResult ValidateAttachmentsDeffered() { var ProjectCode = Session["ProjectCode"].ToString(); var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Form"); if (checkApplicationForm == null) { TempData["error"] = " Please upload Application form"; return RedirectToAction("AttachmentsNewDeffered"); } var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Bank Statement"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload Bank Statement"; return RedirectToAction("AttachmentsNewDeffered"); } var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Board Resolution"); if (checkAttachmentBoard == null) { TempData["error"] = " Please upload Board Resolution"; return RedirectToAction("AttachmentsNewDeffered"); } var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Business Plan"); if (checkAttachmentBusinesP == null) { TempData["error"] = " Please upload Business Plan"; return RedirectToAction("AttachmentsNewDeffered"); } var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "INCORPORATION"); if (checkAttachmentInc == null) { TempData["error"] = " Please upload Certificate of Incorporation"; return RedirectToAction("AttachmentsNewDeffered"); } return RedirectToAction("ResubmitNew"); } public ActionResult ValidateAttachmentsAmendment() { var ProjectCode = Session["ProjectCode"].ToString(); var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Letter"); if (checkApplicationForm == null) { TempData["error"] = " Please upload Application Letter"; return RedirectToAction("AttachmentsAmendments"); } var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "TIC Certificate"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload TIC Certificate"; return RedirectToAction("AttachmentsAmendments"); } var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Brela Offical Search"); if (checkAttachmentBoard == null) { TempData["error"] = " Please upload Brela Offical Search"; return RedirectToAction("AttachmentsAmendments"); } var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Progresss Report"); if (checkAttachmentBusinesP == null) { TempData["error"] = " Please upload Progresss Report"; return RedirectToAction("AttachmentsAmendments"); } var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Pictures of your Project"); if (checkAttachmentInc == null) { TempData["error"] = " Please upload Pictures of your Project"; return RedirectToAction("AttachmentsAmendments"); } return RedirectToAction("PickUpOfficeAmendment"); } public ActionResult ValidateAttachmentsExpansion() { var ProjectCode = Session["ProjectCode"].ToString(); var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Form"); if (checkApplicationForm == null) { TempData["error"] = " Please upload Application form"; return RedirectToAction("AttachmentsExpansion"); } var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Bank Statement"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload Bank Statement"; return RedirectToAction("AttachmentsExpansion"); } var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Board Resolution"); if (checkAttachmentBoard == null) { TempData["error"] = " Please upload Board Resolution"; return RedirectToAction("AttachmentsExpansion"); } var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Business Plan"); if (checkAttachmentBusinesP == null) { TempData["error"] = " Please upload Business Plan"; return RedirectToAction("AttachmentsExpansion"); } var checkAttachmentCert = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "TIC Certificate"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload TIC Certificate"; return RedirectToAction("AttachmentsExpansion"); } var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "INCORPORATION"); if (checkAttachmentInc == null) { TempData["error"] = " Please upload Certificate of Incorporation"; return RedirectToAction("AttachmentsExpansion"); } return RedirectToAction("PickUpOfficeExpansion"); } public ActionResult ValidateAttachmentsAmendmentDeffered() { var ProjectCode = Session["ProjectCode"].ToString(); var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Letter"); if (checkApplicationForm == null) { TempData["error"] = " Please upload Application Letter"; return RedirectToAction("AttachmentsAmendmentDeffered"); } var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "TIC Certificate"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload TIC Certificate"; return RedirectToAction("AttachmentsAmendmentDeffered"); } var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Brela Offical Search"); if (checkAttachmentBoard == null) { TempData["error"] = " Please upload Brela Offical Search"; return RedirectToAction("AttachmentsAmendmentDeffered"); } var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Progresss Report"); if (checkAttachmentBusinesP == null) { TempData["error"] = " Please upload Progresss Report"; return RedirectToAction("AttachmentsAmendmentDeffered"); } var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Pictures of your Project"); if (checkAttachmentInc == null) { TempData["error"] = " Please upload Pictures of your Project"; return RedirectToAction("AttachmentsAmendmentDeffered"); } return RedirectToAction("ResubmitAmendment"); } public ActionResult ValidateAttachmentsExtension() { var ProjectCode = Session["ProjectCode"].ToString(); var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Letter"); if (checkApplicationForm == null) { TempData["error"] = " Please upload Application Letter"; return RedirectToAction("AttachmentsExtension"); } var checkAttachmentAForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application form"); if (checkAttachmentAForm == null) { TempData["error"] = " Please upload Application form "; return RedirectToAction("AttachmentsExtension"); } var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "TIC Certificate"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload TIC Certificate"; return RedirectToAction("AttachmentsExtension"); } var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Brela Offical Search"); if (checkAttachmentBoard == null) { TempData["error"] = " Please upload Brela Offical Search"; return RedirectToAction("AttachmentsExtension"); } var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Progresss Report"); if (checkAttachmentBusinesP == null) { TempData["error"] = " Please upload Progresss Report"; return RedirectToAction("AttachmentsExtension"); } var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Pictures of your Project"); if (checkAttachmentInc == null) { TempData["error"] = " Please upload Pictures of your Project"; return RedirectToAction("AttachmentsExtension"); } TempData["success"] = " Your application has been submitted , waiting for approval before generating control number"; // return RedirectToAction("PickUpOfficeExtension"); //return RedirectToAction("WaitingApproval"); } public ActionResult ValidateAttachmentsExtensionDeffered() { var ProjectCode = Session["ProjectCode"].ToString(); var checkApplicationForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application Letter"); if (checkApplicationForm == null) { TempData["error"] = " Please upload Application Letter"; return RedirectToAction("AttachmentsExtensionDeffered"); } var checkAttachmentBank = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "TIC Certificate"); if (checkAttachmentBank == null) { TempData["error"] = " Please upload TIC Certificate"; return RedirectToAction("AttachmentsExtensionDeffered"); } var checkAttachmentBoard = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Brela Offical Search"); if (checkAttachmentBoard == null) { TempData["error"] = " Please upload Brela Offical Search"; return RedirectToAction("AttachmentsExtensionDeffered"); } var checkAttachmentAForm = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Application form"); if (checkAttachmentAForm == null) { TempData["error"] = " Please upload Application form "; return RedirectToAction("AttachmentsExtensionDeffered"); } var checkAttachmentBusinesP = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Progresss Report"); if (checkAttachmentBusinesP == null) { TempData["error"] = " Please upload Progresss Report"; return RedirectToAction("AttachmentsExtensionDeffered"); } var checkAttachmentInc = myContext.AttachmentsList.SingleOrDefault(t => t.ProjectCode == ProjectCode && t.AttachmentName == "Pictures of your Project"); if (checkAttachmentInc == null) { TempData["error"] = " Please upload Pictures of your Project"; return RedirectToAction("AttachmentsExtensionDeffered"); } TempData["success"] = " Your application has been submitted , waiting for approval before generating control number"; return RedirectToAction("ResubmitExtension"); } [HttpPost] public ActionResult PostAppoloadedFile(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsNew"); } catch (Exception ex) { TempData["error"] = "Error!... Failed to upload attachement"; return RedirectToAction("AttachmentsNew"); } } else { TempData["error"] = "Maximum file size 7Mb"; return RedirectToAction("AttachmentsNew"); } } else { TempData["success"] = model.AttachmentName + " Already uploaded"; return RedirectToAction("AttachmentsNew"); } } else { TempData["error"] = "Please upload pdf file"; return RedirectToAction("AttachmentsNew"); } } [HttpPost] public ActionResult PostAppoloadedFileExpansion(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; ; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsExpansion"); } catch (Exception ex) { TempData["error"] = "Error!...Failed to upload attachement"; return RedirectToAction("AttachmentsExpansion"); } } else { TempData["error"] = "Maximum file size 7Mb"; return RedirectToAction("AttachmentsExpansion"); } } else { TempData["error"] = model.AttachmentName + " Already uploaded"; return RedirectToAction("AttachmentsExpansion"); } } else { TempData["error"] = "Please pdf file only "; return RedirectToAction("AttachmentsExpansion"); } } [HttpPost] public ActionResult PostAppoloadedFileAmendment(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsAmendments"); } catch (Exception ex) { TempData["error"] = "Error!...Failed to upload attachement"; return RedirectToAction("AttachmentsAmendments"); } } else { TempData["error"] = "Maximum file size 7Mb"; return RedirectToAction("AttachmentsAmendments"); } } else { TempData["success"] = model.AttachmentName + " Already Uploaded"; return RedirectToAction("AttachmentsAmendments"); } } else { TempData["error"] = "Please upload pdf documents only"; return RedirectToAction("AttachmentsAmendments"); } } [HttpPost] public ActionResult PostAppoloadedFileAmendmentDeffered(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = GenerateINoCN() + model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsAmendmentDeffered"); } catch (Exception ex) { TempData["error"] = "Error!...Failed to upload attachement"; return RedirectToAction("AttachmentsAmendmentDeffered"); } } else { TempData["error"] = "Maximum file size 7Mb"; return RedirectToAction("AttachmentsAmendmentDeffered"); } } else { TempData["success"] = model.AttachmentName + " Already Uploaded"; return RedirectToAction("AttachmentsAmendmentDeffered"); } } else { TempData["error"] = "Please upload pdf documents only"; return RedirectToAction("AttachmentsAmendmentDeffered"); } } [HttpPost] public ActionResult PostAppoloadedFileExtension(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsExtension"); } catch (Exception ex) { TempData["error"] = "Error!...Failed to upload attachement"; return RedirectToAction("AttachmentsExtension"); } } else { return RedirectToAction("AttachmentsExtension"); } } else { TempData["success"] = model.AttachmentName + " Already Uploaded"; return RedirectToAction("AttachmentsExtension"); } } else { TempData["error"] = "Please upload pdf documents only"; return RedirectToAction("AttachmentsExtension"); } } [HttpPost] public ActionResult PostAppoloadedFileExtensionDeffered(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = GenerateINoCN() + model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsExtensionDeffered"); } catch (Exception ex) { TempData["error"] = "Error!...Failed to upload attachement"; return RedirectToAction("AttachmentsExtensionDeffered"); } } else { return RedirectToAction("AttachmentsExtensionDeffered"); } } else { TempData["success"] = model.AttachmentName + " Already Uploaded"; return RedirectToAction("AttachmentsExtensionDeffered"); } } else { TempData["error"] = "Please upload pdf documents only"; return RedirectToAction("AttachmentsExtensionDeffered"); } } [HttpPost] public ActionResult PostAppoloadedFileNewDeffered(HttpPostedFileBase UploadedPdf, Attachments model) { String FileExt = Path.GetExtension(UploadedPdf.FileName).ToUpper(); if (FileExt == ".PDF") { var ProjectCode = Session["ProjectCode"].ToString(); var checkFileExists = myContext.AttachmentsList.SingleOrDefault(t => t.AttachmentName == model.AttachmentName && t.ProjectCode == ProjectCode); if (checkFileExists == null) { string fileName = null; string path = @"\\192.168.2.32\Attachments\" + Session["ProjectCode"].ToString(); if (model.UploadedPdf != null && model.UploadedPdf.ContentLength > 0 && model.UploadedPdf.ContentLength <= 7000000) { try { fileName = GenerateINoCN() + model.AttachmentName + FileExt; if (!Directory.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(path); Directory.CreateDirectory(path); } string newpath = Path.Combine(path, fileName); UploadedPdf.SaveAs(newpath); Attachments addAttchment = new Attachments(); addAttchment.AttachmentPath = Session["ProjectCode"].ToString() + "/" + fileName; addAttchment.ProjectCode = Session["ProjectCode"].ToString(); addAttchment.UploadedBy = Session["CompanyEmail"].ToString(); addAttchment.UploadedDate = DateTime.Now; addAttchment.AttachmentName = model.AttachmentName; myContext.AttachmentsList.Add(addAttchment); myContext.SaveChangesAsync(); TempData["success"] = model.AttachmentName + " successfully saved"; return RedirectToAction("AttachmentsNewDeffered"); } catch (Exception ex) { TempData["error"] = "Error!...Failed to upload attachement"; return RedirectToAction("AttachmentsNewDeffered"); } } else { return RedirectToAction("AttachmentsNewDeffered"); } } else { TempData["success"] = model.AttachmentName + " Already uploaded"; return RedirectToAction("AttachmentsNewDeffered"); } } else { TempData["error"] = "Please upload pdf file"; return RedirectToAction("AttachmentsNewDeffered"); } } public ActionResult LoadgeNewCOI() { var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); var Username = Session["CompanyEmail"].ToString(); var checkCMProfile = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); if (checkCMProfile != null) { StepsManagement stManager = new StepsManagement(); stManager.CompanyName = checkCMProfile.CompanyName; stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = checkCMProfile.CompanyTIN; stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; stManager.ApplicationType = "New"; Session["CompanyName"] = checkCMProfile.CompanyName; Session["CompanyTIN"] = checkCMProfile.CompanyTIN; Session["ProjectCode"] = GenerateINo(); stManager.ProjectCode = Session["ProjectCode"].ToString(); myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); var pobj = new ProjectRepository(); var _birthObjectp = pobj.CreateLocation(); return View("ProjectDetails", _birthObjectp); } return View("LoadgeNewCOI", _birthObject); } public ActionResult LoadgeNewExpansion() { var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); var Username = Session["CompanyEmail"].ToString(); var checkCMProfile = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); if (checkCMProfile != null) { StepsManagement stManager = new StepsManagement(); stManager.CompanyName = checkCMProfile.CompanyName; stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = checkCMProfile.CompanyTIN; stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.ApplicationType = "Expansion"; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; Session["CompanyName"] = checkCMProfile.CompanyName; Session["CompanyTIN"] = checkCMProfile.CompanyTIN; Session["ProjectCode"] = GenerateINo(); stManager.ProjectCode = Session["ProjectCode"].ToString(); myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); var pobj = new ProjectRepository(); var _birthObjectp = pobj.CreateLocation(); return View("ExpansionProject", _birthObjectp); } return View("LoadgeNewExpansion", _birthObject); } public ActionResult LoadgeNewAmendment() { var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); var Username = Session["CompanyEmail"].ToString(); var checkCMProfile = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); if (checkCMProfile != null) { StepsManagement stManager = new StepsManagement(); stManager.CompanyName = checkCMProfile.CompanyName; stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = checkCMProfile.CompanyTIN; stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.ApplicationType = "Amendment"; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; Session["CompanyName"] = checkCMProfile.CompanyName; Session["CompanyTIN"] = checkCMProfile.CompanyTIN; Session["ProjectCode"] = GenerateINo(); stManager.ProjectCode = Session["ProjectCode"].ToString(); myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); var pobj = new ProjectRepository(); var _birthObjectp = pobj.CreateLocation(); return View("AmendmentApplication"); } return View("LoadgeNewAmendment", _birthObject); } public ActionResult LoadgeNewExtesion() { var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); var Username = Session["CompanyEmail"].ToString(); var checkCMProfile = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); if (checkCMProfile != null) { StepsManagement stManager = new StepsManagement(); stManager.CompanyName = checkCMProfile.CompanyName; stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = checkCMProfile.CompanyTIN; stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.ApplicationType = "Extension"; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; Session["CompanyName"] = checkCMProfile.CompanyName; Session["CompanyTIN"] = checkCMProfile.CompanyTIN; Session["ProjectCode"] = GenerateINo(); stManager.ProjectCode = Session["ProjectCode"].ToString(); myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); var pobj = new ProjectRepository(); var _birthObjectp = pobj.CreateLocation(); return View("Extension"); } return View("LoadgeNewExtesion", _birthObject); } public ActionResult ProjectDetails() { var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); Session["InvestorNo"] = GenerateINo(); return View("ProjectDetails", _birthObject); } public ActionResult ShowCompleteCompany() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowCompleteCompanyExtension() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowCompleteCompanyExpansion() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowAmendmentDetails() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.CompanyAmmendmentsExternal.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); return View(checkIfExists); } public ActionResult ShowExtensionDetails() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.CompanyAmmendmentsExternal.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); return View(checkIfExists); } public ActionResult ShowCompleteCompanyAmendment() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowFinancingProfile() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.FinancingProfilesExternals.SingleOrDefault(t => t.ProjectCode == ProjectCode.ToString()); var checkIfPExists = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode.ToString()); var obj = new FinancingRepository(); var objC = new Countries(); var _birthObject = obj.CreateCountry(); IEnumerable selectForeignCountry = from s in _birthObject.ListofForeignEquity // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.SourceCountryEquity), Text = checkIfExists.SourceCountryEquity, Value = checkIfExists.SourceCountryEquity }; checkIfExists.ListofForeignEquity = objC.GetCountries(); IEnumerable selectForeignLoan = from s in _birthObject.ListofForeignLoan select new SelectListItem { Selected = (s.Text == checkIfExists.SourceCountryLoan), Text = checkIfExists.SourceCountryLoan, Value = checkIfExists.SourceCountryLoan }; checkIfExists.ListofForeignLoan = objC.GetCountries(); Session["TypeOfOwnership"] = checkIfPExists.TypeofOwnership; return View(checkIfExists); } public ActionResult ShowErrorPage() { return View(); } public ActionResult ShowFinancingProfileExpansion() { var Username = Session["CompanyEmail"]; var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.FinancingProfilesExternals.SingleOrDefault(t => t.ProjectCode == ProjectCode.ToString()); var obj = new FinancingRepository(); var objC = new Countries(); var _birthObject = obj.CreateCountry(); IEnumerable selectForeignCountry = from s in _birthObject.ListofForeignEquity // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.SourceCountryEquity), Text = checkIfExists.SourceCountryEquity, Value = checkIfExists.SourceCountryEquity }; checkIfExists.ListofForeignEquity = objC.GetCountries(); IEnumerable selectForeignLoan = from s in _birthObject.ListofForeignLoan select new SelectListItem { Selected = (s.Text == checkIfExists.SourceCountryLoan), Text = checkIfExists.SourceCountryLoan, Value = checkIfExists.SourceCountryLoan }; checkIfExists.ListofForeignLoan = objC.GetCountries(); return View(checkIfExists); } public IEnumerable GetListofRegionsEdit(string RegionName) { using (var context1 = new OSSDBContext()) { List Attachment = context1.Regions.AsNoTracking() .Select(n => new SelectListItem { Value = n.RegionName, Text = n.RegionName }).ToList(); var countrytip2 = new SelectListItem() { Value = RegionName, Text = RegionName }; Attachment.Insert(0, countrytip2); return new SelectList(Attachment, "Value", "Text"); } } public ActionResult ShowProjectDetails() { var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.ProjectProfilesExternal.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = GetListofRegionsEdit(checkIfExists.Region); IEnumerable SelectSectors = from s in _birthObject.ListofSectors // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Sector), Text = checkIfExists.Sector, Value = checkIfExists.Sector }; checkIfExists.ListofSectors = SelectSectors; IEnumerable SelectSubSector = from s in _birthObject.ListofSubectors // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.SubSector), Text = checkIfExists.SubSector, Value = checkIfExists.SubSector }; checkIfExists.ListofSubectors = SelectSubSector; IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowDMDetailsDetails() { var Username = Session["CompanyEmail"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = GetListofRegionsEdit(checkIfExists.Region); checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowDMDetailsDetailsDetails() { var Username = Session["CompanyEmail"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowDMDetailsDetailsExtension() { var Username = Session["CompanyEmail"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowDMDetailsDetailsExpansion() { var Username = Session["CompanyEmail"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowProjectDetailsExpansion() { var ProjectCode = Session["ProjectCode"]; var checkIfExists = myContext.ProjectProfilesExternal.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; IEnumerable SelectSectors = from s in _birthObject.ListofSectors // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Sector), Text = checkIfExists.Sector, Value = checkIfExists.Sector }; checkIfExists.ListofSectors = SelectSectors; IEnumerable SelectSubSector = from s in _birthObject.ListofSubectors // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.SubSector), Text = checkIfExists.SubSector, Value = checkIfExists.SubSector }; checkIfExists.ListofSubectors = SelectSubSector; IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult ShowDMDetailsDetailsAmendment() { var Username = Session["CompanyEmail"]; var checkIfExists = myContext.CompanyProfileExternal.Where(t => t.AddedBy == Username.ToString()).SingleOrDefault(); var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); IEnumerable selectListRegion = from s in _birthObject.ListofRegions // where ever you get this from, database etc. select new SelectListItem { Selected = (s.Text == checkIfExists.Region), Text = checkIfExists.Region, Value = checkIfExists.Region }; checkIfExists.ListofRegions = selectListRegion; checkIfExists.IncorpCertDate.ToString(); IEnumerable selectListDistrict = from t in _birthObject.ListofDistricts // where ever you get this from, database etc. select new SelectListItem { Selected = (t.Text == checkIfExists.District), Text = checkIfExists.District, Value = checkIfExists.District }; checkIfExists.ListofDistricts = selectListDistrict; IEnumerable selectListWard = from y in _birthObject.ListofWards // where ever you get this from, database etc. select new SelectListItem { Selected = (y.Text == checkIfExists.Ward), Text = checkIfExists.Ward, Value = checkIfExists.Ward }; checkIfExists.ListofWards = selectListWard; return View(checkIfExists); } public ActionResult FinancingDetailsExternal() { var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("FinancingDetailsExternal", _birthObject); } public ActionResult FinancingDetailsExpansion() { var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("FinancingDetailsExpansion", _birthObject); } public ActionResult RedirectCompany() { var Username = Session["CompanyEmail"].ToString(); var checkIfExist = myContext.CompanyProfileExternal.SingleOrDefault(t => t.AddedBy == Username && t.CleaningStatus == "Submitted"); if (checkIfExist != null) { return RedirectToAction("ShowCompleteCompany", "NewCOI"); } return RedirectToAction("ShowDMDetailsDetails", "NewCOI"); } public ActionResult RedirectCompanyExpansion() { var Username = Session["CompanyEmail"].ToString(); var checkIfExist = myContext.CompanyProfileExternal.SingleOrDefault(t => t.AddedBy == Username && t.CleaningStatus == "Submitted"); if (checkIfExist != null) { return RedirectToAction("ShowCompleteCompanyExpansion", "NewCOI"); } return RedirectToAction("ShowDMDetailsDetailsExpansion", "NewCOI"); } public ActionResult RedirectCompanyAmendment() { var Username = Session["CompanyEmail"].ToString(); var checkIfExist = myContext.CompanyProfileExternal.SingleOrDefault(t => t.AddedBy == Username && t.CleaningStatus == "Submitted"); if (checkIfExist != null) { return RedirectToAction("ShowCompleteCompanyAmendment", "NewCOI"); } return RedirectToAction("ShowDMDetailsDetailsAmendment", "NewCOI"); } public ActionResult RedirectCompanyExtension() { var Username = Session["CompanyEmail"].ToString(); var checkIfExist = myContext.CompanyProfileExternal.SingleOrDefault(t => t.AddedBy == Username && t.CleaningStatus == "Submitted"); if (checkIfExist != null) { return RedirectToAction("ShowCompleteCompanyExtension", "NewCOI"); } return RedirectToAction("ShowDMDetailsDetailsExtension", "NewCOI"); } public ActionResult RedirectProject() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { return RedirectToAction("ShowProjectDetails", "NewCOI"); } return RedirectToAction("ProjectDetails", "NewCOI"); } public ActionResult RedirectProjectExpansion() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { return RedirectToAction("ShowProjectDetailsExpansion", "NewCOI"); } return RedirectToAction("ExpansionProject", "NewCOI"); } public ActionResult RedirectProjectAmendment() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { return RedirectToAction("ShowAmendmentDetails", "NewCOI"); } return RedirectToAction("AmendmentApplication", "NewCOI"); } public ActionResult RedirectProjectExtension() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { return RedirectToAction("ShowExtensionDetails", "NewCOI"); } return RedirectToAction("Extension", "NewCOI"); } public ActionResult RedirectFinancing() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.FinancingProfilesExternals.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { return RedirectToAction("ShowFinancingProfile", "NewCOI"); } return RedirectToAction("FinancingDetailsExternal", "NewCOI"); } public ActionResult RedirectFinancingExpansion() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.FinancingProfilesExternals.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { return RedirectToAction("ShowFinancingProfileExpansion", "NewCOI"); } return RedirectToAction("FinancingDetailsExpansion", "NewCOI"); } public ActionResult AttachmentsNew() { return View("AttachmentsNew"); } public ActionResult AttachmentsNewDeffered() { return View("AttachmentsNewDeffered"); } public ActionResult AttachmentsExpansion() { return View("AttachmentsExpansion"); } public ActionResult AttachmentsAmendments() { return View("AttachmentsAmendments"); } public ActionResult AttachmentsAmendmentDeffered() { return View("AttachmentsAmendmentDeffered"); } public ActionResult AttachmentsExtension() { return View("AttachmentsExtension"); } public ActionResult AttachmentsExtensionDeffered() { return View("AttachmentsExtensionDeffered"); } [HttpPost] public ActionResult WaitingApproval(ApplicationManager model) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); var checkAmentExist = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist == null) { var getPDetails = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); ApplicationManager inv = new ApplicationManager(); inv.ProjectCode = ProjectCode; inv.ProjectName = getPDetails.ProjectName; inv.CompanyName = getPDetails.CompanyName; // Changes to remove hardcoded exchange rates ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency == model.Currency); COIPrice coiPrice = myContext.COIPrices.SingleOrDefault(t => t.ApplicationType == "Extension"); if(exchangeRate != null && coiPrice != null){ decimal Price = coiPrice.Price * exchangeRate.Rate; string priceStr = Price.ToString(); priceStr = priceStr.Contains(".") ? priceStr.TrimEnd('0').TrimEnd('.') : priceStr; inv.Amount = Price; Session["Amount"] = priceStr; Session["AmountinWords"] = CurrencyUtils.ToWords(Price)+" "+exchangeRate.CurrencyDesc; Session["Currency"] = model.Currency; inv.Currency = model.Currency; inv.Station = model.Station; inv.ServiceName = Session["ServiceName"].ToString(); inv.MobileNo = checkApplicant.Mobile; inv.CreatedDate = DateTime.Now; inv.CompanyTIN = Session["CompanyTIN"].ToString(); inv.CompanyEmail = Username; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "Completed"; checkSteps.SubmittedStatus = "Submitted"; checkSteps.UpdatedDate = DateTime.Now; checkAmentExist.ApprovalStatus = "Waiting_Approval"; myContext.ApplicationManagers.Add(inv); myContext.SaveChanges(); } return RedirectToAction("ExtensionIndex"); } else { return RedirectToAction("ExtensionIndex"); } } public ActionResult ResubmitExtension() { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); var checkAmentExist = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { var getPDetails = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); getPDetails.AssignedStatus = "Investor_Returned"; checkIfExist.EvaluationStatus = "Investor_Returned"; checkAmentExist.ApprovalStatus = "Waiting_Approval"; myContext.SaveChanges(); TempData["success"] = "Application successfully returned for evaluation"; return RedirectToAction("ExtensionIndex"); } else { return RedirectToAction("ExtensionIndex"); } } public ActionResult ResubmitAmendment() { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkAmendDetails = myContext.CompanyAmmendments.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); var checkAmentExist = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { var getPDetails = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); checkAmendDetails.CurrentlyWith = "Returned"; checkAmendDetails.ProcessingStatus = "DIF"; checkIfExist.EvaluationStatus = "DIF"; checkAmentExist.ApprovalStatus = "DIF"; myContext.SaveChanges(); TempData["success"] = "Application successfully returned for evaluation"; return RedirectToAction("IndexAmendment"); } else { return RedirectToAction("IndexAmendment"); } } public ActionResult ResubmitNew() { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); var checkPExist = myContext.ProjectProfiles.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExist != null) { checkIfExist.EvaluationStatus = "DIF"; checkPExist.ProcessingStatus = "DIF"; checkPExist.CurrentlyWith = "Returned"; myContext.ApplicationManagers.AddOrUpdate(); myContext.ProjectProfiles.AddOrUpdate(); myContext.SaveChanges(); TempData["success"] = "Application successfully returned for evaluation"; return View("Index"); } else { return View("Index"); } } private void EnsurePaymentSessionDefaults(string currencyIfUnset = "") { if (Session["Currency"] == null) Session["Currency"] = currencyIfUnset; if (Session["Amount"] == null) Session["Amount"] = ""; if (Session["AmountinWords"] == null) Session["AmountinWords"] = ""; } private bool TrySaveInvoice(OSSDBContext ctx, ApplicationManager inv, CompanyProfileExternal company, out string error) { error = null; try { ctx.ApplicationManagers.Add(inv); if (company != null) { company.CleaningStatus = "Submitted"; } ctx.SaveChanges(); return true; } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var msgs = ex.EntityValidationErrors .SelectMany(e => e.ValidationErrors) .Select(e => e.PropertyName + ": " + e.ErrorMessage); error = "Validation failed: " + string.Join("; ", msgs); return false; } catch (Exception ex) { error = ex.Message; return false; } } public ActionResult Payment(ApplicationManager model) { try { if (Session["CompanyEmail"] == null || Session["ProjectCode"] == null) { ViewBag.Error = "Your session expired. Please login again."; return RedirectToAction("Index", "Home"); } if (string.IsNullOrWhiteSpace(model?.Currency)) { ViewBag.Error = "Currency is required."; EnsurePaymentSessionDefaults(); return View("Payment"); } var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var serviceName = ((Session["ServiceName"] as string) ?? string.Empty).Trim(); // Normalize service name to match tblService keys (e.g., "Application for New Certificate" -> "New") var rawService = serviceName; if (rawService.IndexOf("new", StringComparison.OrdinalIgnoreCase) >= 0) { serviceName = "New"; } else if (rawService.IndexOf("expansion", StringComparison.OrdinalIgnoreCase) >= 0) { serviceName = "Expansion"; } // Enforce TZS only as requested model.Currency = "TZS"; // Pre-compute amount from tblService (before early returns), single-row fetch (no iteration) var getPDetailsEarly = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (getPDetailsEarly != null) { var ownershipRawEarly = (getPDetailsEarly.TypeofOwnership ?? "").Trim(); var isLocalEarly = ownershipRawEarly.Equals("Local", StringComparison.OrdinalIgnoreCase); var isForeignOrMixedEarly = ownershipRawEarly.Equals("Foreign", StringComparison.OrdinalIgnoreCase) || ownershipRawEarly.Equals("JV", StringComparison.OrdinalIgnoreCase) || ownershipRawEarly.Equals("Mixed", StringComparison.OrdinalIgnoreCase) || ownershipRawEarly.Equals("Mixed (Foreigners & Tanzanians)", StringComparison.OrdinalIgnoreCase); var serviceKeyEarly = serviceName; if (!isLocalEarly && isForeignOrMixedEarly) serviceKeyEarly = serviceName + "_Foreign"; var feeRow = myContext.ServiceFees.FirstOrDefault(s => s.ServiceName == serviceKeyEarly); if (feeRow != null && feeRow.Fee.HasValue && feeRow.Fee.Value > 0) { TempData["PreAmountTZS"] = feeRow.Fee.Value.ToString("0"); } else { TempData["PreAmountTZS"] = null; // force UI error downstream if not configured } } var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkIfCompany = myContext.CompanyProfileExternal.SingleOrDefault(t => t.AddedBy == Username); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); if (checkIfExist == null) { var getPDetails = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (getPDetails == null) { ViewBag.Error = "Project details not found."; EnsurePaymentSessionDefaults(); return View("Payment"); } // Only New/Expansion supported in this TZS ownership block if (!(serviceName.Equals("New", StringComparison.OrdinalIgnoreCase) || serviceName.Equals("Expansion", StringComparison.OrdinalIgnoreCase))) { ViewBag.Error = $"Unsupported ServiceName '{serviceName}'. Expected New/Expansion."; EnsurePaymentSessionDefaults(); return View("Payment"); } ApplicationManager inv = new ApplicationManager(); inv.ProjectCode = ProjectCode; inv.ProjectName = getPDetails.ProjectName; inv.CompanyName = getPDetails.CompanyName; inv.ServiceName = serviceName; inv.MobileNo = checkApplicant?.Mobile; inv.CreatedDate = DateTime.Now; inv.CompanyTIN = Session["CompanyTIN"] != null ? Session["CompanyTIN"].ToString() : null; inv.CompanyEmail = Username; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); if (checkSteps != null) { checkSteps.StepNo = "Completed"; checkSteps.SubmittedStatus = "Submitted"; checkSteps.UpdatedDate = DateTime.Now; } inv.Currency = model.Currency; inv.Station = model.Station; inv.CompanyTIN = Session["CompanyTIN"] != null ? Session["CompanyTIN"].ToString() : null; // Use precomputed amount from tblService or fallback (saved in TempData earlier) decimal amountToUse; if (TempData["PreAmountTZS"] != null && decimal.TryParse(TempData["PreAmountTZS"].ToString(), out amountToUse)) { inv.Amount = amountToUse; Session["Amount"] = amountToUse.ToString("0"); Session["AmountinWords"] = CurrencyUtils.ToWords(amountToUse) + " Tanzanian Shillings"; Session["Currency"] = model.Currency; } else { var ownershipForKey = getPDetails.TypeofOwnership != null && getPDetails.TypeofOwnership.Equals("Local", StringComparison.OrdinalIgnoreCase) ? serviceName : serviceName + "_Foreign"; var errMsg = $"Fee not configured in tblService for ServiceName='{ownershipForKey}', Currency='TZS'."; TempData["PaymentError"] = errMsg; ViewBag.Error = errMsg; EnsurePaymentSessionDefaults("TZS"); // Show the appropriate payment page based on service if (serviceName.Equals("Expansion", StringComparison.OrdinalIgnoreCase)) { return View("PaymentExpansion"); } return View("Payment"); } string saveErrX; if (!TrySaveInvoice(myContext, inv, checkIfCompany, out saveErrX)) { ViewBag.Error = "Could not save invoice. " + saveErrX; EnsurePaymentSessionDefaults(model.Currency); return View("Payment"); } if (serviceName.Equals("Expansion", StringComparison.OrdinalIgnoreCase)) { return View("PaymentExpansion"); } return View("Payment"); } else { // Invoice already exists; hydrate session so the view can display values Session["Amount"] = checkIfExist.Amount.ToString("0.##"); Session["Currency"] = checkIfExist.Currency; Session["AmountinWords"] = CurrencyUtils.ToWords(checkIfExist.Amount) + " " + checkIfExist.Currency; return View("Payment"); } } catch (Exception ex) { ViewBag.Error = "Error processing payment. " + ex.Message; EnsurePaymentSessionDefaults(); return View("Payment"); } } [HttpPost] public ActionResult PaymentAmendment(ApplicationManager model) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); if (checkIfExist == null) { var getPDetails = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); ApplicationManager inv = new ApplicationManager(); inv.ProjectCode = ProjectCode; inv.ProjectName = getPDetails.ProjectName; inv.CompanyName = getPDetails.CompanyName; inv.ServiceName = Session["ServiceName"].ToString(); inv.MobileNo = checkApplicant.Mobile; inv.CreatedDate = DateTime.Now; inv.Currency = model.Currency; inv.Station = model.Station; inv.CompanyTIN = Session["CompanyTIN"].ToString(); // Changes to remove hardcoded exchange rates ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency == model.Currency); COIPrice coiPrice = myContext.COIPrices.SingleOrDefault(t => t.ApplicationType == "Amendment"); if(exchangeRate != null && coiPrice != null){ decimal Price = coiPrice.Price * exchangeRate.Rate; string priceStr = Price.ToString(); priceStr = priceStr.Contains(".") ? priceStr.TrimEnd('0').TrimEnd('.') : priceStr; inv.Amount = Price; Session["Amount"] = priceStr; Session["AmountinWords"] = CurrencyUtils.ToWords(Price)+" "+exchangeRate.CurrencyDesc; Session["Currency"] = model.Currency; inv.CompanyEmail = Username; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "Completed"; checkSteps.SubmittedStatus = "Submitted"; checkSteps.UpdatedDate = DateTime.Now; myContext.ApplicationManagers.Add(inv); myContext.SaveChanges(); } return View("PaymentAmendment"); } else { return View("PaymentAmendment"); } } public ActionResult PaymentExtension() { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkApplicant = myContext.InvestorExternl.SingleOrDefault(t => t.CompanyEmail == Username); if (checkIfExist == null) { var getPDetails = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); ApplicationManager inv = new ApplicationManager(); inv.ProjectCode = ProjectCode; inv.ProjectName = getPDetails.ProjectName; inv.CompanyName = getPDetails.CompanyName; inv.ServiceName = Session["ServiceName"].ToString(); inv.MobileNo = checkApplicant.Mobile; inv.CreatedDate = DateTime.Now; inv.CompanyTIN = Session["CompanyTIN"].ToString(); COIPrice coiPrice = myContext.COIPrices.SingleOrDefault(t => t.ApplicationType == "Extension"); decimal Price = coiPrice.Price; inv.Amount = Price; string priceStr = Price.ToString(); priceStr = priceStr.Contains(".") ? priceStr.TrimEnd('0').TrimEnd('.') : priceStr; Session["Amount"] = priceStr; inv.CompanyEmail = Username; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "Completed"; checkSteps.SubmittedStatus = "Submitted"; checkSteps.UpdatedDate = DateTime.Now; myContext.ApplicationManagers.Add(inv); myContext.SaveChanges(); return View("PaymentExtension"); } else { return View("PaymentExtension"); } } public ActionResult PaymentExpansion() { return View("PaymentExpansion"); } // Create an additional payment invoice (e.g., surcharge when ownership underpayment occurs) [Authorize] public ActionResult AdditionalPayment(string projectCode = null) { try { var username = Session["CompanyEmail"] as string; if (string.IsNullOrWhiteSpace(username)) { return RedirectToAction("Index", "Home"); } // Prefer explicit project code if provided, otherwise fall back to session var code = !string.IsNullOrWhiteSpace(projectCode) ? projectCode : (Session["ProjectCode"] as string); if (string.IsNullOrWhiteSpace(code)) { TempData["PaymentError"] = "No project selected. Open a project first or pass ?projectCode=..."; EnsurePaymentSessionDefaults("TZS"); return RedirectToAction("Payment"); } // Find the parent application using ProjectCode var parentApplication = myContext.ApplicationManagers .Where(a => a.ProjectCode == code) .OrderByDescending(a => a.CreatedDate) .FirstOrDefault(); if (parentApplication == null) { TempData["PaymentError"] = "Parent application not found for this project code."; EnsurePaymentSessionDefaults("TZS"); return RedirectToAction("Payment"); } // Resolve additional amount and GFSCode from tblService (ServiceName='Additional_Amount', Currency='TZS', Status='1') decimal addAmount = 0m; string gfsCode = "142201370002"; // Default fallback try { var feeRow = myContext.ServiceFees .AsNoTracking() .FirstOrDefault(s => (s.Status ?? "").Trim() == "1" && (s.Currency ?? "").Trim().ToUpper() == "TZS" && (s.ServiceName ?? "").Trim() == "Additional_Amount"); if (feeRow != null && feeRow.Fee.HasValue && feeRow.Fee.Value > 0m) { addAmount = feeRow.Fee.Value; if (!string.IsNullOrWhiteSpace(feeRow.GFSCode)) gfsCode = feeRow.GFSCode; } } catch { // handled below } if (addAmount <= 0m) { var err = "Fee not configured in tblService for ServiceName='Additional_Amount', Currency='TZS'."; TempData["PaymentError"] = err; EnsurePaymentSessionDefaults("TZS"); return RedirectToAction("Payment"); } // Check if additional invoice already exists in tblInvoice var existingInvoiceId = myContext.Database.SqlQuery( "SELECT TOP 1 InvoiceID FROM tblInvoice WHERE ApplicationCode = @p0 AND SubServiceName LIKE 'Additional_Amount%' ORDER BY InvoiceID DESC", code).FirstOrDefault(); if (existingInvoiceId.HasValue) { // Get the existing invoice details var invoiceDetails = myContext.Database.SqlQuery( "SELECT Amount, Currency FROM tblInvoice WHERE InvoiceID = @p0", existingInvoiceId.Value).FirstOrDefault(); if (invoiceDetails != null) { Session["Amount"] = invoiceDetails.Amount.ToString(); var currency = invoiceDetails.Currency ?? "TZS"; Session["Currency"] = currency; Session["AmountinWords"] = CurrencyUtils.ToWords(Convert.ToDecimal(invoiceDetails.Amount)) + " " + currency; } ViewBag.HideAdditionalButton = true; TempData["HidePaidInvoices"] = true; TempData["AdditionalContext"] = true; return View("Payment"); } // Generate BillItemRefNo (using timestamp and project code) string billItemRefNo = "BILL-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + code; // Determine ServiceTypeID (default to 1, adjust if needed based on business logic) int serviceTypeID = 1; // Insert directly into tblInvoice using the parent application details string sql = @" INSERT INTO [dbo].[tblInvoice] ([FullName],[PhoneNo],[GFSCode],[BillItemRefNo],[SubServiceName],[Amount],FrontUserId,ApplicationID,StartDate,Expiredate,ServiceTypeID,ApplicationCode,[Currency],[TIN_No]) VALUES (@FullName,@PhoneNo,@GFSCode,@BillItemRefNo,@SubServiceName,@Amount,@FrontUserId,@ApplicationID,GETDATE(),DATEADD(day,30,GETDATE()),@ServiceTypeID,@ApplicationCode,@Currency,@TIN_No)"; int rowsAffected = myContext.Database.ExecuteSqlCommand(sql, new SqlParameter("@FullName", (object)parentApplication.FullName ?? DBNull.Value), new SqlParameter("@PhoneNo", (object)parentApplication.MobileNo ?? DBNull.Value), new SqlParameter("@GFSCode", (object)gfsCode ?? DBNull.Value), new SqlParameter("@BillItemRefNo", (object)billItemRefNo ?? DBNull.Value), new SqlParameter("@SubServiceName", (object)"Additional_Amount" ?? DBNull.Value), new SqlParameter("@Amount", addAmount), new SqlParameter("@FrontUserId", (object)username ?? DBNull.Value), new SqlParameter("@ApplicationID", (object)parentApplication.ApplicationID ?? DBNull.Value), new SqlParameter("@ServiceTypeID", serviceTypeID), new SqlParameter("@ApplicationCode", (object)code ?? DBNull.Value), new SqlParameter("@Currency", "TZS"), new SqlParameter("@TIN_No", (object)parentApplication.CompanyTIN ?? DBNull.Value) ); if (rowsAffected <= 0) { TempData["PaymentError"] = "Could not create additional payment invoice in tblInvoice."; EnsurePaymentSessionDefaults("TZS"); return RedirectToAction("Payment"); } Session["Amount"] = addAmount.ToString("0"); Session["Currency"] = "TZS"; Session["AmountinWords"] = CurrencyUtils.ToWords(addAmount) + " Tanzanian Shillings"; // In Additional Payment context: hide the "Pay Additional Amount" button and hide previous paid invoices ViewBag.HideAdditionalButton = true; TempData["HidePaidInvoices"] = true; TempData["AdditionalContext"] = true; return View("Payment"); } catch (Exception ex) { TempData["PaymentError"] = "Error creating additional payment invoice. " + ex.Message; EnsurePaymentSessionDefaults("TZS"); return RedirectToAction("Payment"); } } public async Task GenerateControlNo() { await Task.Delay(4000); return View(); } [ValidateAntiForgeryToken] [HttpPost] public async Task ProceControlNumber() { var Username = Session["CompanyEmail"] as string; var ProjectCode = Session["ProjectCode"] as string; var Currency = Session["Currency"] as string; if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(ProjectCode)) { TempData["PaymentError"] = "Your session expired or project is missing. Please login and open the project again."; return RedirectToAction("Payment", "NewCOI"); } var getPDetails = myContext.ApplicationManagers .Where(t => t.ProjectCode == ProjectCode) .OrderByDescending(t => t.CreatedDate) .FirstOrDefault(); if (getPDetails == null) { TempData["PaymentError"] = "No invoice found for this project. Create an invoice first."; return RedirectToAction("Payment", "NewCOI"); } ExchangeRate exchangeRate = myContext.ExchangeRates .FirstOrDefault(t => t.Currency == getPDetails.Currency); if(exchangeRate != null){ Session["EqAmount"] = exchangeRate.Rate * getPDetails.Amount; } else { TempData["error"] = "Couldn\'t process control number. Contact Administrators"; return RedirectToAction("GenerateControlNo", "NewCOI"); } try { getPDetails.UpdatedDate = DateTime.Now; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var mymodel = new mymodel { gepgCtrlno = new gepgCtrlno() { BillId = getPDetails.InvoiceID.ToString(), BillAmt = getPDetails.Amount.ToString(), BillEqvAmt = Session["EqAmount"].ToString(), BillExprDt = DateTime.Now.AddDays(30).ToString("yyyy-MM-ddTHH:mm:ss"), PyrId = getPDetails.CompanyName.ToString(), PyrName = getPDetails.CompanyName.ToString(), BillGenDt = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"), PyrCellNum = getPDetails.MobileNo.ToString(), Ccy = getPDetails.Currency.ToString(), BillDesc = getPDetails.ServiceName.ToString(), BillItems = new BillItems { BillItem = new List { new BillItem { BillItemRef = getPDetails.InvoiceID.ToString() , BillItemAmt=getPDetails.Amount.ToString(), BillItemEqvAmt=Session["EqAmount"].ToString(), GfsCode="142201370002"} } }, systemInfo = new systemInfo { SpSysId = "TTIC003", SpCode = "SP536", SubSpCode = "1002" } } }; var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(mymodel)); var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await client.PostAsync("http://192.168.2.31:8090/tic/generate-controlno", httpContent); var responseJson = await responseMessage.Content.ReadAsStringAsync(); var jObject = JObject.Parse(responseJson); return RedirectToAction("GenerateControlNo", "NewCOI"); } } catch (Exception ex) { var getGepgResponse = myContext.ApplicationManagers .Where(t => t.ProjectCode == ProjectCode) .OrderByDescending(t => t.CreatedDate) .FirstOrDefault(); TempData["error"] = "Network timeout..please try again"; return RedirectToAction("GenerateControlNo", "NewCOI"); } } public ActionResult ExpansionProject() { var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ExpansionProject", _birthObject); } public ActionResult ProceedNext(string TrackingNo) { var checkData = myContext.StepsManagements.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); var checkType = myContext.ProjectProfilesExternal.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); Session["CompanyTIN"] = checkData.CompanyTIN; Session["CompanyName"] = checkData.CompanyName; Session["ProjectCode"] = checkData.ProjectCode; Session["ServiceName"] = checkData.ApplicationType; if (checkData.StepNo == "1") { return RedirectToAction("ProjectDetails"); } if (checkData.StepNo == "2") { Session["TypeofOwnership"] = checkType.TypeofOwnership; return RedirectToAction("FinancingDetailsExternal"); } if (checkData.StepNo == "3") { Session["ServiceName"] = checkType.ServiceName; return RedirectToAction("AttachmentsNew"); } return View("Index"); } public ActionResult RegenerateCNAmendment(string TrackingNo) { var checkData = myContext.ApplicationManagers.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); if (checkData != null) { string priceStr = checkData.Amount.ToString(); priceStr = priceStr.Contains(".") ? priceStr.TrimEnd('0').TrimEnd('.') : priceStr; Session["CompanyTIN"] = checkData.CompanyTIN; Session["CompanyName"] = checkData.CompanyName; Session["ProjectCode"] = checkData.ProjectCode; Session["ServiceName"] = checkData.ServiceName; Session["Currency"] = checkData.Currency; Session["Amount"] = priceStr; Session["AmountinWords"] = CurrencyUtils.ToWords(checkData.Amount); // Changes to remove hardcoded exchange rates ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency == checkData.Currency); if(exchangeRate != null){ Session["AmountinWords"] += " "+exchangeRate.CurrencyDesc; } return View("PaymentAmendment"); } return View("IndexAmendment"); } public ActionResult RegenerateCN(string TrackingNo) { var checkData = myContext.ApplicationManagers.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); if (checkData != null) { string priceStr = checkData.ToString(); priceStr = priceStr.Contains(".") ? priceStr.TrimEnd('0').TrimEnd('.') : priceStr; Session["CompanyTIN"] = checkData.CompanyTIN; Session["CompanyName"] = checkData.CompanyName; Session["ProjectCode"] = checkData.ProjectCode; Session["ServiceName"] = checkData.ServiceName; Session["Currency"] = checkData.Currency; Session["Amount"] = priceStr; Session["AmountinWords"] = CurrencyUtils.ToWords(checkData.Amount); // Changes to remove hardcoded exchange rates ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency == checkData.Currency); if(exchangeRate != null){ Session["AmountinWords"] += " "+exchangeRate.CurrencyDesc; } return View("Payment"); } return View("Index"); } public ActionResult ProceedNextExpansion(string TrackingNo) { var checkData = myContext.StepsManagements.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); var checkType = myContext.ProjectProfilesExternal.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); Session["CompanyTIN"] = checkData.CompanyTIN; Session["CompanyName"] = checkData.CompanyName; Session["ProjectCode"] = checkData.ProjectCode; Session["ServiceName"] = checkData.ApplicationType; if (checkData.StepNo == "1") { return RedirectToAction("LoadgeNewExpansion"); } if (checkData.StepNo == "2") { Session["TypeofOwnership"] = checkType.TypeofOwnership; return RedirectToAction("FinancingDetailsExpansion"); } if (checkData.StepNo == "3") { Session["ServiceName"] = checkType.ServiceName; return RedirectToAction("AttachmentsExpansion"); } return View("Index"); } public ActionResult ProceedNextAmendment(string TrackingNo) { var checkData = myContext.StepsManagements.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); Session["CompanyTIN"] = checkData.CompanyTIN; Session["CompanyName"] = checkData.CompanyName; Session["ProjectCode"] = checkData.ProjectCode; Session["ServiceName"] = checkData.ApplicationType; if (checkData.StepNo == "1") { return RedirectToAction("AmendmentApplication"); } if (checkData.StepNo == "2") { return RedirectToAction("AttachmentsAmendments"); } return View("Index"); } public ActionResult ProceedNextExtention(string TrackingNo) { var checkData = myContext.StepsManagements.Where(t => t.ProjectCode == TrackingNo).SingleOrDefault(); Session["CompanyTIN"] = checkData.CompanyTIN; Session["CompanyName"] = checkData.CompanyName; Session["ProjectCode"] = checkData.ProjectCode; Session["ServiceName"] = checkData.ApplicationType; if (checkData.StepNo == "1") { return RedirectToAction("Extension"); } if (checkData.StepNo == "2") { return RedirectToAction("AttachmentsExtension"); } return View("Index"); } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostProjectProfile(ProjectProfileExternal model) { try { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"]; var checkIfPExists = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode.ToString()); ProjectProfileExternal addnewPProfile = new ProjectProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); Session["CompanyTIN"] = checkIfExists.CompanyTIN; Session["CompanyName"] = checkIfExists.CompanyName; Session["ServiceName"] = "New"; if (ModelState.IsValid) { if (checkIfPExists == null) addnewPProfile.ProjectName = model.ProjectName; addnewPProfile.TypeofOwnership = model.TypeofOwnership; addnewPProfile.UnitMeasure = model.UnitMeasure; addnewPProfile.MainActivity = model.MainActivity; addnewPProfile.Region = model.Region; addnewPProfile.District = model.District; addnewPProfile.ServiceName = Session["ServiceName"].ToString(); addnewPProfile.Email = model.ContactEmail; addnewPProfile.Mobile = model.Mobile; addnewPProfile.ProductionCapacity = model.ProductionCapacity; addnewPProfile.Ward = model.Ward; addnewPProfile.Sector = model.Sector; addnewPProfile.SubSector = model.SubSector; addnewPProfile.MenForeign = model.MenForeign; addnewPProfile.WomenForeign = model.WomenForeign; addnewPProfile.MenLocal = model.MenLocal; addnewPProfile.PostalAddress = model.PostalAddress; addnewPProfile.ContactMobile = model.ContactMobile; addnewPProfile.WomenLocal = model.WomenLocal; addnewPProfile.Street = model.Street; addnewPProfile.AreaType = model.AreaType; addnewPProfile.Area = model.Area; addnewPProfile.LandMarkType = model.LandMarkType; addnewPProfile.LandMarkDescription = model.LandMarkDescription; addnewPProfile.PlotNumber = model.PlotNumber; addnewPProfile.LastUpdateDate = DateTime.Now; addnewPProfile.UpdatedBy = Session["CompanyEmail"].ToString(); addnewPProfile.Telephone = model.ContactMobile; addnewPProfile.CompanyTIN = Session["CompanyTIN"].ToString(); addnewPProfile.CompanyName = Session["CompanyName"].ToString(); addnewPProfile.BlockPlotNumber = model.BlockPlotNumber; addnewPProfile.HouseNo = model.HouseNo; addnewPProfile.StepName = "2"; addnewPProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewPProfile.CreatedDate = DateTime.Now; addnewPProfile.ContactPerson = model.ContactPerson; addnewPProfile.ContactEmail = model.ContactEmail; addnewPProfile.ProjectCode = Session["ProjectCode"].ToString(); addnewPProfile.Title = model.Title; Session["TypeofOwnership"] = model.TypeofOwnership; TempData["success"] = "Project Information Successfully Saved"; myContext.ProjectProfilesExternal.Add(addnewPProfile); var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "2"; checkSteps.ApplicationType = "New"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; if (checkIfPExists == null) { myContext.SaveChanges(); return RedirectToAction("FinancingDetailsExternal"); } else { checkIfPExists.ProjectName = model.ProjectName; checkIfPExists.TypeofOwnership = model.TypeofOwnership; checkIfPExists.UnitMeasure = model.UnitMeasure; checkIfPExists.MainActivity = model.MainActivity; checkIfPExists.Region = model.Region; checkIfPExists.District = model.District; checkIfPExists.ServiceName = Session["ServiceName"].ToString(); checkIfPExists.Email = model.ContactEmail; checkIfPExists.Mobile = model.Mobile; checkIfPExists.ProductionCapacity = model.ProductionCapacity; checkIfPExists.Ward = model.Ward; checkIfPExists.Sector = model.Sector; checkIfPExists.SubSector = model.SubSector; checkIfPExists.MenForeign = model.MenForeign; checkIfPExists.WomenForeign = model.WomenForeign; checkIfPExists.MenLocal = model.MenLocal; checkIfPExists.PostalAddress = model.PostalAddress; checkIfPExists.ContactMobile = model.ContactMobile; checkIfPExists.WomenLocal = model.WomenLocal; checkIfPExists.Street = model.Street; checkIfPExists.AreaType = model.AreaType; checkIfPExists.Area = model.Area; checkIfPExists.LandMarkType = model.LandMarkType; checkIfPExists.LandMarkDescription = model.LandMarkDescription; checkIfPExists.PlotNumber = model.PlotNumber; checkIfPExists.LastUpdateDate = DateTime.Now; checkIfPExists.UpdatedBy = Session["CompanyEmail"].ToString(); checkIfPExists.Telephone = model.ContactMobile; checkIfPExists.CompanyTIN = Session["CompanyTIN"].ToString(); checkIfPExists.CompanyName = Session["CompanyName"].ToString(); checkIfPExists.BlockPlotNumber = model.BlockPlotNumber; checkIfPExists.HouseNo = model.HouseNo; checkIfPExists.StepName = "2"; checkIfPExists.AddedBy = Session["CompanyEmail"].ToString(); checkIfPExists.CreatedDate = DateTime.Now; checkIfPExists.ContactPerson = model.ContactPerson; checkIfPExists.ContactEmail = model.ContactEmail; checkIfPExists.ProjectCode = Session["ProjectCode"].ToString(); checkIfPExists.Title = model.Title; myContext.SaveChanges(); return RedirectToAction("FinancingDetailsExternal"); } } else { TempData["error"] = "Your inputs have some errors! correct and retry."; TempData["validation_errors"] = ModelState.ToDictionary( k => k.Key, v => v.Value.Errors.Select(x => x.ErrorMessage).ToArray()); var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ProjectDetails", _birthObject); } } catch (DbEntityValidationException ex) { IDictionary errorsDictionary = new Dictionary(); foreach (var validationErrors in ex.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { if (!errorsDictionary.ContainsKey(validationError.PropertyName)) { errorsDictionary[validationError.PropertyName] = new string[] { validationError.ErrorMessage }; } else { errorsDictionary[validationError.PropertyName] = errorsDictionary[validationError.PropertyName] .Concat(new string[] { validationError.ErrorMessage }).ToArray(); } } } TempData["error"] = "Your inputs have some errors! correct and retry."; TempData["validation_errors"] = errorsDictionary; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ProjectDetails", _birthObject); } catch (Exception ex) { TempData["error"] = "Unexpected error occured! Please retry"; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ProjectDetails", _birthObject); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostProjectProfileChange(ProjectProfileExternal model) { try { if (ModelState.IsValid) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); var checkProjectDetails = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkIfExists != null){ if (checkProjectDetails != null){ // ProjectProfileExternal addnewPProfile = new ProjectProfileExternal(); Session["CompanyTIN"] = checkIfExists.CompanyTIN; Session["CompanyName"] = checkIfExists.CompanyName; Session["ServiceName"] = "New"; checkProjectDetails.ProjectName = model.ProjectName; checkProjectDetails.TypeofOwnership = model.TypeofOwnership; checkProjectDetails.UnitMeasure = model.UnitMeasure; checkProjectDetails.MainActivity = model.MainActivity; checkProjectDetails.Region = model.Region; checkProjectDetails.District = model.District; checkProjectDetails.ServiceName = Session["ServiceName"].ToString(); checkProjectDetails.Email = model.ContactEmail; checkProjectDetails.Mobile = model.Mobile; checkProjectDetails.ProductionCapacity = model.ProductionCapacity; checkProjectDetails.Ward = model.Ward; checkProjectDetails.Sector = model.Sector; checkProjectDetails.SubSector = model.SubSector; checkProjectDetails.MenForeign = model.MenForeign; checkProjectDetails.WomenForeign = model.WomenForeign; checkProjectDetails.MenLocal = model.MenLocal; checkProjectDetails.PostalAddress = model.PostalAddress; checkProjectDetails.ContactMobile = model.ContactMobile; checkProjectDetails.WomenLocal = model.WomenLocal; checkProjectDetails.Street = model.Street; checkProjectDetails.AreaType = model.AreaType; checkProjectDetails.Area = model.Area; checkProjectDetails.LandMarkType = model.LandMarkType; checkProjectDetails.LandMarkDescription = model.LandMarkDescription; checkProjectDetails.PlotNumber = model.PlotNumber; checkProjectDetails.LastUpdateDate = DateTime.Now; checkProjectDetails.UpdatedBy = Session["CompanyEmail"].ToString(); checkProjectDetails.Telephone = model.ContactMobile; checkProjectDetails.CompanyTIN = Session["CompanyTIN"].ToString(); checkProjectDetails.CompanyName = Session["CompanyName"].ToString(); checkProjectDetails.BlockPlotNumber = model.BlockPlotNumber; checkProjectDetails.HouseNo = model.HouseNo; checkProjectDetails.StepName = "2"; checkProjectDetails.AddedBy = Session["CompanyEmail"].ToString(); checkProjectDetails.CreatedDate = DateTime.Now; checkProjectDetails.ContactPerson = model.ContactPerson; checkProjectDetails.ContactEmail = model.ContactEmail; checkProjectDetails.ProjectCode = Session["ProjectCode"].ToString(); checkProjectDetails.Title = model.Title; Session["TypeofOwnership"] = model.TypeofOwnership; TempData["success"] = "Project Information Successfully Saved"; myContext.SaveChanges(); return RedirectToAction("RedirectFinancing"); } else { TempData["error"] = "Project with code "+ProjectCode+" does not exist"; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ShowProjectDetails", _birthObject); } } else { TempData["error"] = "Company with TIN "+model.CompanyTIN+" is not yet registered at TIC"; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ShowProjectDetails", _birthObject); } } else { TempData["error"] = "Your inputs have some errors! correct and retry."; TempData["validation_errors"] = ModelState.ToDictionary( k => k.Key, v => v.Value.Errors.Select(x => x.ErrorMessage).ToArray()); var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ShowProjectDetails", _birthObject); } } catch (DbEntityValidationException ex) { IDictionary errorsDictionary = new Dictionary(); foreach (var validationErrors in ex.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { if (!errorsDictionary.ContainsKey(validationError.PropertyName)) { errorsDictionary[validationError.PropertyName] = new string[] { validationError.ErrorMessage }; } else { errorsDictionary[validationError.PropertyName] = errorsDictionary[validationError.PropertyName] .Concat(new string[] { validationError.ErrorMessage }).ToArray(); } } } TempData["error"] = "Your inputs have some errors! correct and retry."; TempData["validation_errors"] = errorsDictionary; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ShowProjectDetails", _birthObject); } catch (Exception ex) { TempData["error"] = "Unexpected error occured! Please retry"; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ShowProjectDetails", _birthObject); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostAmendmentApplication(CompanyAmmendmentExternal model) { var Username = Session["CompanyEmail"].ToString(); CompanyAmmendmentExternal addnewAmendment = new CompanyAmmendmentExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); Session["CompanyTIN"] = checkIfExists.CompanyTIN; Session["CompanyName"] = checkIfExists.CompanyName; Session["ServiceName"] = "Amendment"; addnewAmendment.ChangeofCompanyName = model.ChangeofCompanyName; addnewAmendment.ChangeOfLocation = model.ChangeOfLocation; addnewAmendment.ChangeofImplementationPeriod = model.ChangeofImplementationPeriod; addnewAmendment.LostCertificate = model.LostCertificate; addnewAmendment.ReIssueCertificate = model.ReIssueCertificate; addnewAmendment.CompanyName = checkIfExists.CompanyName; addnewAmendment.ProjectName = model.ProjectName; addnewAmendment.CompanyTIN = checkIfExists.CompanyTIN; addnewAmendment.ChangeofShareholders = model.ChangeofShareholders; addnewAmendment.ChangeOfAddress = model.ChangeOfAddress; addnewAmendment.CertificateNo = model.CertificateNo; addnewAmendment.IssuedDate = model.IssuedDate; addnewAmendment.ProjectCode = Session["ProjectCode"].ToString(); addnewAmendment.LoadgeBy = Session["ProjectCode"].ToString(); addnewAmendment.CreatedDate = DateTime.Now; addnewAmendment.LoadgeBy = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"]; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "2"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; TempData["success"] = "Project Information Successfully Saved"; var checkIfAExists = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode.ToString()); if (checkIfAExists == null) { myContext.CompanyAmmendmentsExternal.Add(addnewAmendment); myContext.SaveChanges(); return RedirectToAction("AttachmentsAmendments"); } else { checkIfAExists.ChangeofCompanyName = model.ChangeofCompanyName; checkIfAExists.ChangeOfLocation = model.ChangeOfLocation; checkIfAExists.ChangeofImplementationPeriod = model.ChangeofImplementationPeriod; checkIfAExists.LostCertificate = model.LostCertificate; checkIfAExists.ReIssueCertificate = model.ReIssueCertificate; checkIfAExists.CompanyName = checkIfExists.CompanyName; checkIfAExists.ProjectName = model.ProjectName; checkIfAExists.CompanyTIN = checkIfExists.CompanyTIN; checkIfAExists.ChangeofShareholders = model.ChangeofShareholders; checkIfAExists.ChangeOfAddress = model.ChangeOfAddress; checkIfAExists.CertificateNo = model.CertificateNo; checkIfAExists.IssuedDate = model.IssuedDate; checkIfAExists.ProjectCode = Session["ProjectCode"].ToString(); checkIfAExists.LoadgeBy = Session["ProjectCode"].ToString(); checkIfAExists.CreatedDate = DateTime.Now; checkIfAExists.LoadgeBy = Session["CompanyEmail"].ToString(); myContext.SaveChanges(); return RedirectToAction("AttachmentsAmendments"); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostExtension(CompanyAmmendmentExternal model) { var Username = Session["CompanyEmail"].ToString(); CompanyAmmendmentExternal addnewAmendment = new CompanyAmmendmentExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); Session["CompanyTIN"] = checkIfExists.CompanyTIN; Session["CompanyName"] = checkIfExists.CompanyName; Session["ServiceName"] = "Extension"; addnewAmendment.ChangeofCompanyName = model.ChangeofCompanyName; addnewAmendment.ChangeOfLocation = model.ChangeOfLocation; addnewAmendment.ChangeofImplementationPeriod = model.ChangeofImplementationPeriod; addnewAmendment.LostCertificate = model.LostCertificate; addnewAmendment.ReIssueCertificate = model.ReIssueCertificate; addnewAmendment.CompanyName = checkIfExists.CompanyName; addnewAmendment.ProjectName = model.ProjectName; addnewAmendment.CompanyTIN = checkIfExists.CompanyTIN; addnewAmendment.ChangeofShareholders = model.ChangeofShareholders; addnewAmendment.ChangeOfAddress = model.ChangeOfAddress; addnewAmendment.CertificateNo = model.CertificateNo; addnewAmendment.Reason = model.Reason; addnewAmendment.IssuedDate = model.IssuedDate; addnewAmendment.ProjectCode = Session["ProjectCode"].ToString(); addnewAmendment.LoadgeBy = Session["ProjectCode"].ToString(); addnewAmendment.CreatedDate = DateTime.Now; addnewAmendment.LoadgeBy = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"]; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "2"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; TempData["success"] = "Project Information Successfully Saved"; var checkIfAExists = myContext.CompanyAmmendmentsExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode.ToString()); if (checkIfAExists == null) { myContext.CompanyAmmendmentsExternal.Add(addnewAmendment); myContext.SaveChanges(); return RedirectToAction("AttachmentsExtension"); } else { checkIfAExists.ChangeofCompanyName = model.ChangeofCompanyName; checkIfAExists.ChangeOfLocation = model.ChangeOfLocation; checkIfAExists.ChangeofImplementationPeriod = model.ChangeofImplementationPeriod; checkIfAExists.LostCertificate = model.LostCertificate; checkIfAExists.ReIssueCertificate = model.ReIssueCertificate; checkIfAExists.CompanyName = checkIfExists.CompanyName; checkIfAExists.ProjectName = model.ProjectName; checkIfAExists.CompanyTIN = checkIfExists.CompanyTIN; checkIfAExists.ChangeofShareholders = model.ChangeofShareholders; checkIfAExists.ChangeOfAddress = model.ChangeOfAddress; checkIfAExists.CertificateNo = model.CertificateNo; checkIfAExists.Reason = model.Reason; checkIfAExists.IssuedDate = model.IssuedDate; checkIfAExists.ProjectCode = Session["ProjectCode"].ToString(); checkIfAExists.LoadgeBy = Session["ProjectCode"].ToString(); checkIfAExists.CreatedDate = DateTime.Now; checkIfAExists.LoadgeBy = Session["CompanyEmail"].ToString(); myContext.SaveChanges(); return RedirectToAction("AttachmentsExtension"); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostProjectProfileExpansion(ProjectProfileExternal model) { var Username = Session["CompanyEmail"].ToString(); ProjectProfileExternal addnewPProfile = new ProjectProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); Session["CompanyTIN"] = checkIfExists.CompanyTIN; Session["CompanyName"] = checkIfExists.CompanyName; Session["ServiceName"] = "Expansion"; addnewPProfile.ProjectName = model.ProjectName; addnewPProfile.TypeofOwnership = model.TypeofOwnership; addnewPProfile.UnitMeasure = model.UnitMeasure; addnewPProfile.MainActivity = model.MainActivity; addnewPProfile.Region = model.Region; addnewPProfile.District = model.District; addnewPProfile.ServiceName = Session["ServiceName"].ToString(); addnewPProfile.Email = model.ContactEmail; addnewPProfile.Mobile = model.ContactMobile; addnewPProfile.TICCertificateNo = model.TICCertificateNo; addnewPProfile.IssuedDate = model.IssuedDate; addnewPProfile.ProductionCapacity = model.ProductionCapacity; addnewPProfile.Ward = model.Ward; addnewPProfile.Sector = model.Sector; addnewPProfile.SubSector = model.SubSector; addnewPProfile.MenForeign = model.MenForeign; addnewPProfile.WomenForeign = model.WomenForeign; addnewPProfile.MenLocal = model.MenLocal; addnewPProfile.PostalAddress = model.PostalAddress; addnewPProfile.ContactMobile = model.ContactMobile; addnewPProfile.WomenLocal = model.WomenLocal; addnewPProfile.Street = model.Street; addnewPProfile.AreaType = model.AreaType; addnewPProfile.Area = model.Area; addnewPProfile.LandMarkType = model.LandMarkType; addnewPProfile.LandMarkDescription = model.LandMarkDescription; addnewPProfile.PlotNumber = model.PlotNumber; addnewPProfile.LastUpdateDate = DateTime.Now; addnewPProfile.UpdatedBy = Session["CompanyEmail"].ToString(); addnewPProfile.Telephone = model.ContactMobile; addnewPProfile.CompanyTIN = Session["CompanyTIN"].ToString(); addnewPProfile.CompanyName = Session["CompanyName"].ToString(); addnewPProfile.BlockPlotNumber = model.BlockPlotNumber; addnewPProfile.HouseNo = model.HouseNo; addnewPProfile.StepName = "2"; addnewPProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewPProfile.CreatedDate = DateTime.Now; addnewPProfile.ContactPerson = model.ContactPerson; addnewPProfile.OriginalCOI = model.OriginalCOI; addnewPProfile.IssuedDate = model.IssuedDate; addnewPProfile.ContactEmail = model.ContactEmail; addnewPProfile.ProjectCode = Session["ProjectCode"].ToString(); addnewPProfile.Title = model.Title; Session["TypeofOwnership"] = model.TypeofOwnership; TempData["success"] = "Project Information Successfully Saved"; myContext.ProjectProfilesExternal.Add(addnewPProfile); var ProjectCode = Session["ProjectCode"]; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "2"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; myContext.SaveChanges(); return RedirectToAction("FinancingDetailsExpansion"); } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostProjectProfileExpansionChange(ProjectProfileExternal model) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); ProjectProfileExternal addnewPProfile = new ProjectProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); var checkIfPExists = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); Session["CompanyTIN"] = checkIfExists.CompanyTIN; Session["CompanyName"] = checkIfExists.CompanyName; Session["ServiceName"] = "Expansion"; checkIfPExists.ProjectName = model.ProjectName; checkIfPExists.TypeofOwnership = model.TypeofOwnership; checkIfPExists.UnitMeasure = model.UnitMeasure; checkIfPExists.MainActivity = model.MainActivity; checkIfPExists.Region = model.Region; checkIfPExists.District = model.District; checkIfPExists.ServiceName = Session["ServiceName"].ToString(); checkIfPExists.Email = model.ContactEmail; checkIfPExists.Mobile = model.ContactMobile; checkIfPExists.TICCertificateNo = model.TICCertificateNo; checkIfPExists.IssuedDate = model.IssuedDate; checkIfPExists.ProductionCapacity = model.ProductionCapacity; checkIfPExists.Ward = model.Ward; checkIfPExists.Sector = model.Sector; checkIfPExists.SubSector = model.SubSector; checkIfPExists.MenForeign = model.MenForeign; checkIfPExists.WomenForeign = model.WomenForeign; checkIfPExists.MenLocal = model.MenLocal; checkIfPExists.PostalAddress = model.PostalAddress; checkIfPExists.ContactMobile = model.ContactMobile; checkIfPExists.WomenLocal = model.WomenLocal; checkIfPExists.Street = model.Street; checkIfPExists.AreaType = model.AreaType; checkIfPExists.Area = model.Area; checkIfPExists.LandMarkType = model.LandMarkType; checkIfPExists.LandMarkDescription = model.LandMarkDescription; checkIfPExists.PlotNumber = model.PlotNumber; checkIfPExists.LastUpdateDate = DateTime.Now; checkIfPExists.UpdatedBy = Session["CompanyEmail"].ToString(); checkIfPExists.Telephone = model.ContactMobile; checkIfPExists.CompanyTIN = Session["CompanyTIN"].ToString(); checkIfPExists.CompanyName = Session["CompanyName"].ToString(); checkIfPExists.BlockPlotNumber = model.BlockPlotNumber; checkIfPExists.HouseNo = model.HouseNo; checkIfPExists.AddedBy = Session["CompanyEmail"].ToString(); checkIfPExists.CreatedDate = DateTime.Now; checkIfPExists.ContactPerson = model.ContactPerson; checkIfPExists.OriginalCOI = model.OriginalCOI; checkIfPExists.IssuedDate = model.IssuedDate; checkIfPExists.ContactEmail = model.ContactEmail; checkIfPExists.ProjectCode = Session["ProjectCode"].ToString(); checkIfPExists.Title = model.Title; Session["TypeofOwnership"] = model.TypeofOwnership; TempData["success"] = "Project Information Successfully Saved"; myContext.SaveChanges(); return RedirectToAction("RedirectFinancingExpansion"); } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfile(CompanyProfileExternal model) { try { var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfSaved = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN && t.AddedBy != Username); if (checkIfSaved != null) { TempData["error"] = "Failed to save Company Details, Company already exists created by " + checkIfSaved.AddedBy; var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); return View("LoadgeNewCOI", _birthObject); } else { var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN && t.AddedBy == Username); if (checkIfExists == null) { addnewCMProfile.CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName); addnewCMProfile.CompanyTIN = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); addnewCMProfile.Category = Sanitizer.GetSafeHtmlFragment(model.Category); addnewCMProfile.IncorpCertNo = Sanitizer.GetSafeHtmlFragment(model.IncorpCertNo); addnewCMProfile.IncorpCertDate = model.IncorpCertDate; addnewCMProfile.Region = model.Region; addnewCMProfile.District = model.District; addnewCMProfile.Ward = model.Ward; addnewCMProfile.CompanyEmail = Sanitizer.GetSafeHtmlFragment(model.CompanyEmail); addnewCMProfile.CompanyMobile = Sanitizer.GetSafeHtmlFragment(model.CompanyMobile); addnewCMProfile.Street = Sanitizer.GetSafeHtmlFragment(model.Street); addnewCMProfile.PostalAddress = Sanitizer.GetSafeHtmlFragment(model.PostalAddress); addnewCMProfile.AreaType = Sanitizer.GetSafeHtmlFragment(model.AreaType); addnewCMProfile.Area = Sanitizer.GetSafeHtmlFragment(model.Area); addnewCMProfile.LandMarkType = Sanitizer.GetSafeHtmlFragment(model.LandMarkType); addnewCMProfile.LandMarkDescription = Sanitizer.GetSafeHtmlFragment(model.LandMarkDescription); addnewCMProfile.PlotNumber = Sanitizer.GetSafeHtmlFragment(model.PlotNumber); addnewCMProfile.Telephone = Sanitizer.GetSafeHtmlFragment(model.Telephone); addnewCMProfile.BlockPlotNumber = Sanitizer.GetSafeHtmlFragment(model.BlockPlotNumber); addnewCMProfile.HouseNo = Sanitizer.GetSafeHtmlFragment(model.HouseNo); addnewCMProfile.StepName = "1"; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; addnewCMProfile.OperatingStatus = "Operating"; Session["CompanyName"] = Sanitizer.GetSafeHtmlFragment(model.CompanyName); Session["CompanyTIN"] = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); Session["ProjectCode"] = GenerateINo(); var getInvestorProfile = myContext.InvestorExternl.Where(t => t.CompanyEmail == Username).SingleOrDefault(); getInvestorProfile.CompanyTIN = model.CompanyTIN; getInvestorProfile.CompanyName = model.CompanyName; TempData["success"] = "Company Information Successfully Saved"; myContext.CompanyProfileExternal.Add(addnewCMProfile); StepsManagement stManager = new StepsManagement(); stManager.ProjectCode = Session["ProjectCode"].ToString(); stManager.CompanyName = Session["CompanyName"].ToString(); stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = Session["CompanyTIN"].ToString(); stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; stManager.ApplicationType = "New"; myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); TempData["success"] = "Project profile page"; return RedirectToAction("RedirectProject"); } else { TempData["error"] = "Failed to save Company Details, Company already exists created by " + checkIfExists.AddedBy; var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); return View("LoadgeNewCOI", _birthObject); } } } catch (Exception ex) { TempData["error"] = "Error!....failed to register company"; var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); return View("LoadgeNewCOI", _birthObject); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfileUpdate(CompanyProfileExternal model) { try { //if (ModelState.IsValid) //{ var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN && t.AddedBy == Username); if (checkIfExists != null) { checkIfExists.CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName); checkIfExists.CompanyTIN = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); checkIfExists.Category = Sanitizer.GetSafeHtmlFragment(model.Category); checkIfExists.IncorpCertNo = Sanitizer.GetSafeHtmlFragment(model.IncorpCertNo); checkIfExists.IncorpCertDate = model.IncorpCertDate; checkIfExists.Region = model.Region; checkIfExists.District = model.District; checkIfExists.Ward = model.Ward; checkIfExists.CompanyEmail = Sanitizer.GetSafeHtmlFragment(model.CompanyEmail); checkIfExists.CompanyMobile = Sanitizer.GetSafeHtmlFragment(model.CompanyMobile); checkIfExists.Street = Sanitizer.GetSafeHtmlFragment(model.Street); checkIfExists.PostalAddress = Sanitizer.GetSafeHtmlFragment(model.PostalAddress); checkIfExists.AreaType = Sanitizer.GetSafeHtmlFragment(model.AreaType); checkIfExists.Area = Sanitizer.GetSafeHtmlFragment(model.Area); checkIfExists.LandMarkType = Sanitizer.GetSafeHtmlFragment(model.LandMarkType); checkIfExists.LandMarkDescription = Sanitizer.GetSafeHtmlFragment(model.LandMarkDescription); checkIfExists.PlotNumber = Sanitizer.GetSafeHtmlFragment(model.PlotNumber); checkIfExists.Telephone = Sanitizer.GetSafeHtmlFragment(model.Telephone); checkIfExists.BlockPlotNumber = Sanitizer.GetSafeHtmlFragment(model.BlockPlotNumber); checkIfExists.HouseNo = Sanitizer.GetSafeHtmlFragment(model.HouseNo); addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; myContext.SaveChanges(); TempData["success"] = "Project profile page"; return RedirectToAction("RedirectProject"); } else { TempData["error"] = "Failed to update Company Profiles"; var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); return View("LoadgeNewCOI", _birthObject); } } catch (Exception ex) { TempData["error"] = "Error!....failed to register company"; var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); return View("LoadgeNewCOI", _birthObject); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfileExpansion(CompanyProfileExternal model) { if (ModelState.IsValid) { var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); if (checkIfExists == null) { addnewCMProfile.CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName); addnewCMProfile.CompanyTIN = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); addnewCMProfile.Category = Sanitizer.GetSafeHtmlFragment(model.Category); addnewCMProfile.IncorpCertNo = Sanitizer.GetSafeHtmlFragment(model.IncorpCertNo); addnewCMProfile.IncorpCertDate = model.IncorpCertDate; addnewCMProfile.Region = model.Region; addnewCMProfile.District = model.District; addnewCMProfile.Ward = model.Ward; addnewCMProfile.CompanyEmail = Sanitizer.GetSafeHtmlFragment(model.CompanyEmail); addnewCMProfile.CompanyMobile = Sanitizer.GetSafeHtmlFragment(model.CompanyMobile); addnewCMProfile.Street = Sanitizer.GetSafeHtmlFragment(model.Street); addnewCMProfile.PostalAddress = Sanitizer.GetSafeHtmlFragment(model.PostalAddress); addnewCMProfile.AreaType = Sanitizer.GetSafeHtmlFragment(model.AreaType); addnewCMProfile.Area = Sanitizer.GetSafeHtmlFragment(model.Area); addnewCMProfile.LandMarkType = Sanitizer.GetSafeHtmlFragment(model.LandMarkType); addnewCMProfile.LandMarkDescription = Sanitizer.GetSafeHtmlFragment(model.LandMarkDescription); addnewCMProfile.PlotNumber = Sanitizer.GetSafeHtmlFragment(model.PlotNumber); addnewCMProfile.Telephone = Sanitizer.GetSafeHtmlFragment(model.Telephone); addnewCMProfile.BlockPlotNumber = Sanitizer.GetSafeHtmlFragment(model.BlockPlotNumber); addnewCMProfile.HouseNo = Sanitizer.GetSafeHtmlFragment(model.HouseNo); addnewCMProfile.StepName = "1"; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; addnewCMProfile.OperatingStatus = "Operating"; Session["CompanyName"] = Sanitizer.GetSafeHtmlFragment(model.CompanyName); Session["CompanyTIN"] = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); Session["ProjectCode"] = GenerateINo(); var getInvestorProfile = myContext.InvestorExternl.Where(t => t.CompanyEmail == Username).SingleOrDefault(); getInvestorProfile.CompanyTIN = model.CompanyTIN; getInvestorProfile.CompanyName = model.CompanyName; TempData["success"] = "Company Information Successfully Saved"; myContext.CompanyProfileExternal.Add(addnewCMProfile); StepsManagement stManager = new StepsManagement(); stManager.ProjectCode = Session["ProjectCode"].ToString(); stManager.CompanyName = Session["CompanyName"].ToString(); stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = Session["CompanyTIN"].ToString(); stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); return RedirectToAction("ExpansionProject"); } else { var CheckIfApproved = myContext.ApplicationManagers.Where(t => t.CompanyTIN == model.CompanyTIN); if (CheckIfApproved != null) { checkIfExists.CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName); checkIfExists.CompanyTIN = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); checkIfExists.Category = Sanitizer.GetSafeHtmlFragment(model.Category); checkIfExists.IncorpCertNo = Sanitizer.GetSafeHtmlFragment(model.IncorpCertNo); checkIfExists.IncorpCertDate = model.IncorpCertDate; checkIfExists.Region = model.Region; checkIfExists.District = model.District; checkIfExists.Ward = model.Ward; checkIfExists.CompanyEmail = Sanitizer.GetSafeHtmlFragment(model.CompanyEmail); checkIfExists.CompanyMobile = Sanitizer.GetSafeHtmlFragment(model.CompanyMobile); checkIfExists.Street = Sanitizer.GetSafeHtmlFragment(model.Street); checkIfExists.PostalAddress = Sanitizer.GetSafeHtmlFragment(model.PostalAddress); checkIfExists.AreaType = Sanitizer.GetSafeHtmlFragment(model.AreaType); checkIfExists.Area = Sanitizer.GetSafeHtmlFragment(model.Area); checkIfExists.LandMarkType = Sanitizer.GetSafeHtmlFragment(model.LandMarkType); checkIfExists.LandMarkDescription = Sanitizer.GetSafeHtmlFragment(model.LandMarkDescription); checkIfExists.PlotNumber = Sanitizer.GetSafeHtmlFragment(model.PlotNumber); checkIfExists.Telephone = Sanitizer.GetSafeHtmlFragment(model.Telephone); checkIfExists.BlockPlotNumber = Sanitizer.GetSafeHtmlFragment(model.BlockPlotNumber); checkIfExists.HouseNo = model.HouseNo; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; myContext.SaveChanges(); TempData["success"] = "Project profile page"; return RedirectToAction("RedirectProjectExpansion"); } TempData["success"] = "Project profile page"; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ExpansionProject", _birthObject); } } else { TempData["error"] = "Please fill proper company details"; var obj = new CompanyRepository(); var _birthObject = obj.CreateLocation(); return View("LoadgeNewExpansion", _birthObject); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfileAmendment(CompanyProfileExternal model) { try { var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN); if (checkIfExists == null) { addnewCMProfile.CompanyName = model.CompanyName; addnewCMProfile.CompanyTIN = model.CompanyTIN; addnewCMProfile.Category = model.Category; addnewCMProfile.IncorpCertNo = model.IncorpCertNo; addnewCMProfile.IncorpCertDate = model.IncorpCertDate; addnewCMProfile.Region = model.Region; addnewCMProfile.District = model.District; addnewCMProfile.Ward = model.Ward; addnewCMProfile.CompanyEmail = model.CompanyEmail; addnewCMProfile.CompanyMobile = model.CompanyMobile; addnewCMProfile.Street = model.Street; addnewCMProfile.PostalAddress = model.PostalAddress; addnewCMProfile.AreaType = model.AreaType; addnewCMProfile.Area = model.Area; addnewCMProfile.LandMarkType = model.LandMarkType; addnewCMProfile.LandMarkDescription = model.LandMarkDescription; addnewCMProfile.PlotNumber = model.PlotNumber; addnewCMProfile.Telephone = model.Telephone; addnewCMProfile.BlockPlotNumber = model.BlockPlotNumber; addnewCMProfile.HouseNo = model.HouseNo; addnewCMProfile.StepName = "1"; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; addnewCMProfile.OperatingStatus = "Operating"; Session["CompanyName"] = model.CompanyName; Session["CompanyTIN"] = model.CompanyTIN; Session["ProjectCode"] = GenerateINo(); var getInvestorProfile = myContext.InvestorExternl.Where(t => t.CompanyEmail == Username).SingleOrDefault(); getInvestorProfile.CompanyTIN = model.CompanyTIN; getInvestorProfile.CompanyName = model.CompanyName; TempData["success"] = "Company Information Successfully Saved"; myContext.CompanyProfileExternal.Add(addnewCMProfile); StepsManagement stManager = new StepsManagement(); stManager.ProjectCode = Session["ProjectCode"].ToString(); stManager.CompanyName = Session["CompanyName"].ToString(); stManager.StepNo = "1"; stManager.CreatedDate = DateTime.Now; stManager.ApplicationType = "Amendment"; stManager.CompanyTIN = Session["CompanyTIN"].ToString(); stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); return RedirectToAction("AmendmentApplication"); } else { TempData["error"] = "Failed to save Company Details, Company already exists created by " + checkIfExists.AddedBy; var pobj = new CompanyRepository(); var _birthObjectp = pobj.CreateLocation(); return View("LoadgeNewAmendment", _birthObjectp); } } catch (Exception ex) { TempData["error"] = "Error occured while saving details.. Please contact TIC call centre"; var pobj = new CompanyRepository(); var _birthObjectp = pobj.CreateLocation(); return View("LoadgeNewAmendment", _birthObjectp); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfileExtension(CompanyProfileExternal model) { var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); if (checkIfExists == null) { addnewCMProfile.CompanyName = model.CompanyName; addnewCMProfile.CompanyTIN = model.CompanyTIN; addnewCMProfile.Category = model.Category; addnewCMProfile.IncorpCertNo = model.IncorpCertNo; addnewCMProfile.IncorpCertDate = model.IncorpCertDate; addnewCMProfile.Region = model.Region; addnewCMProfile.District = model.District; addnewCMProfile.Ward = model.Ward; addnewCMProfile.CompanyEmail = model.CompanyEmail; addnewCMProfile.CompanyMobile = model.CompanyMobile; addnewCMProfile.Street = model.Street; addnewCMProfile.PostalAddress = model.PostalAddress; addnewCMProfile.AreaType = model.AreaType; addnewCMProfile.Area = model.Area; addnewCMProfile.LandMarkType = model.LandMarkType; addnewCMProfile.LandMarkDescription = model.LandMarkDescription; addnewCMProfile.PlotNumber = model.PlotNumber; addnewCMProfile.Telephone = model.Telephone; addnewCMProfile.BlockPlotNumber = model.BlockPlotNumber; addnewCMProfile.HouseNo = model.HouseNo; addnewCMProfile.StepName = "1"; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; addnewCMProfile.OperatingStatus = "Operating"; Session["CompanyName"] = model.CompanyName; Session["CompanyTIN"] = model.CompanyTIN; Session["ProjectCode"] = GenerateINo(); var getInvestorProfile = myContext.InvestorExternl.Where(t => t.CompanyEmail == Username).SingleOrDefault(); getInvestorProfile.CompanyTIN = model.CompanyTIN; getInvestorProfile.CompanyName = model.CompanyName; TempData["success"] = "Company Information Successfully Saved"; myContext.CompanyProfileExternal.Add(addnewCMProfile); StepsManagement stManager = new StepsManagement(); stManager.ProjectCode = Session["ProjectCode"].ToString(); stManager.CompanyName = Session["CompanyName"].ToString(); stManager.StepNo = "1"; stManager.ApplicationType = "Extension"; stManager.CreatedDate = DateTime.Now; stManager.CompanyTIN = Session["CompanyTIN"].ToString(); stManager.CompanyEmail = Username; stManager.UpdatedDate = DateTime.Now; stManager.EvaluationStatus = "Company Details"; stManager.SubmittedStatus = "Not Submitted"; myContext.StepsManagements.Add(stManager); myContext.SaveChanges(); return RedirectToAction("Extension"); } else { TempData["success"] = "Project profile page"; return RedirectToAction("Extension"); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfileAmendmentChange(CompanyProfileExternal model) { if (ModelState.IsValid) { var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); if (checkIfExists != null) { var CheckIfApproved = myContext.ApplicationManagers.Where(t => t.CompanyTIN == model.CompanyTIN); if (CheckIfApproved != null) { checkIfExists.CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName); checkIfExists.CompanyTIN = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); checkIfExists.Category = model.Category; checkIfExists.IncorpCertNo = model.IncorpCertNo; checkIfExists.IncorpCertDate = model.IncorpCertDate; checkIfExists.Region = model.Region; checkIfExists.District = model.District; checkIfExists.Ward = model.Ward; checkIfExists.CompanyEmail = model.CompanyEmail; checkIfExists.CompanyMobile = model.CompanyMobile; checkIfExists.Street = model.Street; checkIfExists.PostalAddress = model.PostalAddress; checkIfExists.AreaType = model.AreaType; checkIfExists.Area = model.Area; checkIfExists.LandMarkType = model.LandMarkType; checkIfExists.LandMarkDescription = model.LandMarkDescription; checkIfExists.PlotNumber = model.PlotNumber; checkIfExists.Telephone = model.Telephone; checkIfExists.BlockPlotNumber = model.BlockPlotNumber; checkIfExists.HouseNo = model.HouseNo; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; myContext.SaveChanges(); return RedirectToAction("AmendmentApplication"); } else { TempData["success"] = "Project profile page"; return View("AmendmentApplication"); } } return View("AmendmentApplication"); } else { TempData["error"] = "Failed to save details"; return View("AmendmentApplication"); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostCompanyProfileExtensionChange(CompanyProfileExternal model) { if (ModelState.IsValid) { var Username = Session["CompanyEmail"].ToString(); CompanyProfileExternal addnewCMProfile = new CompanyProfileExternal(); var checkIfExists = myContext.CompanyProfileExternal.SingleOrDefault(t => t.CompanyTIN == model.CompanyTIN || t.AddedBy == Username); if (checkIfExists != null) { var CheckIfApproved = myContext.ApplicationManagers.Where(t => t.CompanyTIN == model.CompanyTIN); if (CheckIfApproved != null) { checkIfExists.CompanyName = Sanitizer.GetSafeHtmlFragment(model.CompanyName); checkIfExists.CompanyTIN = Sanitizer.GetSafeHtmlFragment(model.CompanyTIN); checkIfExists.Category = model.Category; checkIfExists.IncorpCertNo = model.IncorpCertNo; checkIfExists.IncorpCertDate = model.IncorpCertDate; checkIfExists.Region = model.Region; checkIfExists.District = model.District; checkIfExists.Ward = model.Ward; checkIfExists.CompanyEmail = model.CompanyEmail; checkIfExists.CompanyMobile = model.CompanyMobile; checkIfExists.Street = model.Street; checkIfExists.PostalAddress = model.PostalAddress; checkIfExists.AreaType = model.AreaType; checkIfExists.Area = model.Area; checkIfExists.LandMarkType = model.LandMarkType; checkIfExists.LandMarkDescription = model.LandMarkDescription; checkIfExists.PlotNumber = model.PlotNumber; checkIfExists.Telephone = model.Telephone; checkIfExists.BlockPlotNumber = model.BlockPlotNumber; checkIfExists.HouseNo = model.HouseNo; addnewCMProfile.AddedBy = Session["CompanyEmail"].ToString(); addnewCMProfile.CreatedDate = DateTime.Now; myContext.SaveChanges(); return RedirectToAction("Extension"); } else { TempData["success"] = "Project profile page"; return View("Extension"); } } return View("Extension"); } else { TempData["error"] = "Failed to save details"; return View("LoadgeNewExtension"); } } public ActionResult BrowseApplicantDocumentsNew() { var CompanyTIN = Session["CompanyTIN"]; var ProjectCode = Session["ProjectCode"]; return Redirect("/PrintAppProfileNew.aspx?CompanyTIN=" + CompanyTIN + "&ProjectCode=" + ProjectCode); } public ActionResult ProcessReceipt(long ID) { return Redirect("/PrintReceipt.aspx?InvoiceID=" + ID); } public ActionResult BrowseApplicantDocumentsExpansion() { var CompanyTIN = Session["CompanyTIN"]; var ProjectCode = Session["ProjectCode"]; return Redirect("/ProjectAppProfileExpansion.aspx?CompanyTIN=" + CompanyTIN + "&ProjectCode=" + ProjectCode); } public ActionResult BrowseApplicantDocumentsAmendment() { var CompanyTIN = Session["CompanyTIN"]; var ProjectCode = Session["ProjectCode"]; return Redirect("/PrintAppProfileAmendment.aspx?CompanyTIN=" + CompanyTIN + "&ProjectCode=" + ProjectCode); } public ActionResult BrowseApplicantDocumentsExtension() { var CompanyTIN = Session["CompanyTIN"]; var ProjectCode = Session["ProjectCode"]; return Redirect("/PrintAppProfileExtension.aspx?CompanyTIN=" + CompanyTIN + "&ProjectCode=" + ProjectCode); } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostFinancingProfile(FinancingProfileExternal model) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var CompanyTIN = Session["CompanyTIN"].ToString(); FinancingProfileExternal addnewFProfile = new FinancingProfileExternal(); var checkPExists = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkPExists != null) { addnewFProfile.ProjectCode = ProjectCode; addnewFProfile.CompanyTIN = CompanyTIN; addnewFProfile.AddedBy = Username; addnewFProfile.LocalEquity = model.LocalEquity; addnewFProfile.LocalLoan = model.LocalLoan; addnewFProfile.ForeignEquity = model.ForeignEquity; addnewFProfile.SourceCountryEquity = model.SourceCountryEquity; addnewFProfile.ForeignLoan = model.ForeignLoan; addnewFProfile.SourceCountryLoan = model.SourceCountryLoan; addnewFProfile.WorkingCapital = model.WorkingCapital; addnewFProfile.FixedAsset = (model.LocalEquity + model.LocalLoan + model.ForeignEquity + model.ForeignLoan); addnewFProfile.TotalDDI = (model.LocalEquity + model.LocalLoan); addnewFProfile.TotalForeign = model.ForeignEquity + model.ForeignLoan; addnewFProfile.TotalLocal = (model.LocalEquity + model.LocalLoan); addnewFProfile.TotalCapital = (model.WorkingCapital + model.LocalEquity + model.LocalLoan + model.ForeignEquity + model.ForeignLoan); addnewFProfile.MTotalCapital = (addnewFProfile.TotalCapital * 0.000001); addnewFProfile.MLocalEquity = (model.LocalEquity * 0.000001); addnewFProfile.MLocalLoan = (model.LocalLoan * 0.000001); addnewFProfile.MFixedAsset = (addnewFProfile.FixedAsset * 0.000001); addnewFProfile.MTotalDDI = (model.LocalEquity + model.LocalLoan) * (0.000001); addnewFProfile.MTotalForeign = (model.ForeignEquity + model.ForeignLoan) * (0.000001); addnewFProfile.MTotalLocal = (model.LocalEquity + model.LocalLoan) * (0.000001); addnewFProfile.MForeignEquity = model.ForeignEquity * 0.000001; addnewFProfile.MForeignLoan = model.ForeignLoan * 0.000001; addnewFProfile.TotalFDI = (model.ForeignEquity + model.ForeignLoan); addnewFProfile.MInvestmentBreakDown = addnewFProfile.MTotalCapital; addnewFProfile.MWorkingCapital = model.WorkingCapital * 0.000001; addnewFProfile.MTotalFDI = (model.ForeignEquity + model.ForeignLoan) * (0.000001); addnewFProfile.ProjectID = 0; addnewFProfile.Jobs = 0; addnewFProfile.StepName = "3"; addnewFProfile.CreatedDate = DateTime.Now; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "3"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; if ((Session["TypeofOwnership"].ToString() == "Foreign" || Session["TypeofOwnership"].ToString() == "JV") && addnewFProfile.TotalCapital < 500000) { TempData["error"] = "Total Capital should not be less than $500,000"; var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("FinancingDetailsExternal", _birthObject); } if (Session["TypeofOwnership"].ToString() == "Local" && addnewFProfile.TotalCapital < 100000) { TempData["error"] = "Total Capital should not be less than $100,000"; var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("FinancingDetailsExternal", _birthObject); } TempData["success"] = "Financial Information Successfully Updated"; myContext.FinancingProfilesExternals.Add(addnewFProfile); myContext.SaveChanges(); if (Session["ServiceName"].ToString() == "New") { return RedirectToAction("AttachmentsNew"); } return RedirectToAction("AttachmentsExpansion"); } else { TempData["error"] = "Error! failed to add financing"; var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("ShowFinancingProfile", _birthObject); } } [ValidateAntiForgeryToken] [HttpPost] public ActionResult PostFinancingProfileChange(FinancingProfileExternal model) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var CompanyTIN = Session["CompanyTIN"].ToString(); FinancingProfileExternal addnewFProfile = new FinancingProfileExternal(); var checkPExists = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkFExists = myContext.FinancingProfilesExternals.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkPExists != null) { checkFExists.ProjectCode = ProjectCode; checkFExists.CompanyTIN = CompanyTIN; checkFExists.AddedBy = Username; checkFExists.LocalEquity = model.LocalEquity; checkFExists.LocalLoan = model.LocalLoan; checkFExists.ForeignEquity = model.ForeignEquity; checkFExists.SourceCountryEquity = model.SourceCountryEquity; checkFExists.ForeignLoan = model.ForeignLoan; checkFExists.SourceCountryLoan = model.SourceCountryLoan; checkFExists.WorkingCapital = model.WorkingCapital; checkFExists.FixedAsset = (model.LocalEquity + model.LocalLoan + model.ForeignEquity + model.ForeignLoan); checkFExists.TotalDDI = (model.LocalEquity + model.LocalLoan); checkFExists.TotalForeign = model.ForeignEquity + model.ForeignLoan; checkFExists.TotalLocal = (model.LocalEquity + model.LocalLoan); checkFExists.TotalCapital = (model.WorkingCapital + model.LocalEquity + model.LocalLoan + model.ForeignEquity + model.ForeignLoan); checkFExists.MTotalCapital = (addnewFProfile.TotalCapital * 0.000001); checkFExists.MLocalEquity = (model.LocalEquity * 0.000001); checkFExists.MLocalLoan = (model.LocalLoan * 0.000001); checkFExists.MFixedAsset = (addnewFProfile.FixedAsset * 0.000001); checkFExists.MTotalDDI = (model.LocalEquity + model.LocalLoan) * (0.000001); checkFExists.MTotalForeign = (model.ForeignEquity + model.ForeignLoan) * (0.000001); checkFExists.MTotalLocal = (model.LocalEquity + model.LocalLoan) * (0.000001); checkFExists.MForeignEquity = model.ForeignEquity * 0.000001; checkFExists.MForeignLoan = model.ForeignLoan * 0.000001; checkFExists.TotalFDI = (model.ForeignEquity + model.ForeignLoan); checkFExists.MInvestmentBreakDown = addnewFProfile.MTotalCapital; checkFExists.MWorkingCapital = model.WorkingCapital * 0.000001; checkFExists.MTotalFDI = (model.ForeignEquity + model.ForeignLoan) * (0.000001); checkFExists.ProjectID = 0; checkFExists.Jobs = 0; checkFExists.StepName = "3"; checkFExists.CreatedDate = DateTime.Now; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "3"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; if ((Session["TypeofOwnership"].ToString() == "Foreign" || Session["TypeofOwnership"].ToString() == "JV") && checkFExists.TotalCapital < 500000) { TempData["error"] = "Total Capital should not be less than $500,000"; var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("ShowFinancingProfile", _birthObject); } if (Session["TypeofOwnership"].ToString() == "Local" && checkFExists.TotalCapital < 100000) { TempData["error"] = "Total Capital should not be less than $100,000"; var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("ShowFinancingProfile", _birthObject); } TempData["success"] = "Financial Information Successfully Updated"; myContext.SaveChanges(); if (Session["ServiceName"].ToString() == "New") { return RedirectToAction("AttachmentsNew"); } return RedirectToAction("AttachmentsExpansion"); } else { TempData["error"] = "Error! failed to add financing"; var obj = new FinancingRepository(); var _birthObject = obj.CreateCountry(); return View("ShowFinancingProfile", _birthObject); } } public ActionResult PostFinancingProfileChangeExpansion(FinancingProfileExternal model) { var Username = Session["CompanyEmail"].ToString(); var ProjectCode = Session["ProjectCode"].ToString(); var CompanyTIN = Session["CompanyTIN"].ToString(); FinancingProfileExternal addnewFProfile = new FinancingProfileExternal(); var checkPExists = myContext.ProjectProfilesExternal.SingleOrDefault(t => t.ProjectCode == ProjectCode); var checkFExists = myContext.FinancingProfilesExternals.SingleOrDefault(t => t.ProjectCode == ProjectCode); if (checkPExists != null) { checkFExists.ProjectCode = ProjectCode; checkFExists.CompanyTIN = CompanyTIN; checkFExists.AddedBy = Username; checkFExists.LocalEquity = model.LocalEquity; checkFExists.LocalLoan = model.LocalLoan; checkFExists.ForeignEquity = model.ForeignEquity; checkFExists.SourceCountryEquity = model.SourceCountryEquity; checkFExists.ForeignLoan = model.ForeignLoan; checkFExists.SourceCountryLoan = model.SourceCountryLoan; checkFExists.WorkingCapital = model.WorkingCapital; checkFExists.FixedAsset = (model.LocalEquity + model.LocalLoan + model.ForeignEquity + model.ForeignLoan); checkFExists.TotalDDI = (model.LocalEquity + model.LocalLoan); checkFExists.TotalForeign = model.ForeignEquity + model.ForeignLoan; checkFExists.TotalLocal = (model.LocalEquity + model.LocalLoan); checkFExists.TotalCapital = (model.WorkingCapital + model.LocalEquity + model.LocalLoan + model.ForeignEquity + model.ForeignLoan); checkFExists.MTotalCapital = (addnewFProfile.TotalCapital * 0.000001); checkFExists.MLocalEquity = (model.LocalEquity * 0.000001); checkFExists.MLocalLoan = (model.LocalLoan * 0.000001); checkFExists.MFixedAsset = (addnewFProfile.FixedAsset * 0.000001); checkFExists.MTotalDDI = (model.LocalEquity + model.LocalLoan) * (0.000001); checkFExists.MTotalForeign = (model.ForeignEquity + model.ForeignLoan) * (0.000001); checkFExists.MTotalLocal = (model.LocalEquity + model.LocalLoan) * (0.000001); checkFExists.MForeignEquity = model.ForeignEquity * 0.000001; checkFExists.MForeignLoan = model.ForeignLoan * 0.000001; checkFExists.TotalFDI = (model.ForeignEquity + model.ForeignLoan); checkFExists.MInvestmentBreakDown = addnewFProfile.MTotalCapital; checkFExists.MWorkingCapital = model.WorkingCapital * 0.000001; checkFExists.MTotalFDI = (model.ForeignEquity + model.ForeignLoan) * (0.000001); checkFExists.ProjectID = 0; checkFExists.Jobs = 0; checkFExists.StepName = "3"; checkFExists.CreatedDate = DateTime.Now; var checkSteps = myContext.StepsManagements.Where(t => t.ProjectCode == ProjectCode.ToString()).SingleOrDefault(); checkSteps.StepNo = "3"; checkSteps.SubmittedStatus = "Not Submitted"; checkSteps.UpdatedDate = DateTime.Now; TempData["success"] = "Financial Information Successfully Updated"; myContext.SaveChanges(); if (Session["ServiceName"].ToString() == "New") { return RedirectToAction("AttachmentsNew"); } return RedirectToAction("AttachmentsExpansion"); } else { TempData["success"] = "Project profile page"; var obj = new ProjectRepository(); var _birthObject = obj.CreateLocation(); return View("ProjectDetails", _birthObject); } } public string GenerateINo() { Random Ino = new Random(); long ran_no = Ino.Next(1, 10000); DateTime now = DateTime.Now; return "TIC" + now.Year + "-" + ran_no.ToString() + now.Month + now.Day; } public string GenerateINoCN() { Random Ino = new Random(); long ran_no = Ino.Next(1, 100); DateTime now = DateTime.Now; return ran_no.ToString(); } public ActionResult GetCountry() { var repo = new Countries(); IEnumerable regions = repo.GetCountries(); return Json(regions, JsonRequestBehavior.AllowGet); } [HttpGet] public ActionResult GetRegions(long CountryID) { if (!string.IsNullOrWhiteSpace(CountryID.ToString())) { var repo = new RegionRepository(); IEnumerable regions = repo.GetRegions(CountryID); return Json(regions, JsonRequestBehavior.AllowGet); } return null; } public ActionResult GetSubSector(string SectorName) { if (!string.IsNullOrWhiteSpace(SectorName.ToString())) { var repo = new SubSectorsRepository(); IEnumerable sub_Sector = repo.GetSubSectors(SectorName); return Json(sub_Sector, JsonRequestBehavior.AllowGet); } return null; } [HttpGet] public ActionResult GetRegionsD(long CountryID) { if (!string.IsNullOrWhiteSpace(CountryID.ToString())) { var repo = new RegionRepository(); IEnumerable regions = repo.GetRegionsD(CountryID); return Json(regions, JsonRequestBehavior.AllowGet); } return null; } [HttpGet] public ActionResult GetDistricts(string RegionName) { if (!string.IsNullOrWhiteSpace(RegionName)) { var repo = new DistrictRepository(); IEnumerable regions = repo.GetDistrictsNameByRegion(RegionName); return Json(regions, JsonRequestBehavior.AllowGet); } return null; } [HttpGet] public ActionResult GetWard(string DistrictName) { if (!string.IsNullOrWhiteSpace(DistrictName.ToString())) { var repo = new WardRepository(); IEnumerable regions = repo.GetWardOfBirth(DistrictName); return Json(regions, JsonRequestBehavior.AllowGet); } return null; } public ActionResult DisplayInvoice() { return new ViewAsPdf(); } public ActionResult DisplayInvoiceTransfer() { return new ViewAsPdf(); } public ActionResult Regenerate(string Id) { Session["ProjectCode"] = Id; return RedirectToAction("DisplayPDF"); } public ActionResult RegenerateTransfer(string Id) { Session["ProjectCode"] = Id; return RedirectToAction("DisplayInvoiceTransfer"); } public async Task DisplayPDF() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); // Changes to remove hardcoded exchange rates ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency ==checkIfExist.Currency); COIPrice coiPrice = myContext.COIPrices.SingleOrDefault(t => t.ApplicationType == checkIfExist.ServiceName); decimal Price = coiPrice.Price * exchangeRate.Rate; Session["AmountinWords"] = CurrencyUtils.ToWords(Price); var InvoiceID = checkIfExist.InvoiceID; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage responseMessage = await client.GetAsync("http://192.168.2.31:8090/tic/invoice-gen/" + InvoiceID); var responseJson = await responseMessage.Content.ReadAsStringAsync(); var jObject = JObject.Parse(responseJson); var checkresult = jObject.GetValue("resultcode").ToString(); if (checkresult == "0") { Session["ControlNo"] = jObject.SelectToken("result.ControlNo").Value(); Session["QRCode"] = jObject.SelectToken("result.QRCode").Value(); Session["SubServiceName"] = jObject.SelectToken("result.SubServiceName").Value(); Session["FullName"] = jObject.SelectToken("result.FullName").Value(); Session["CompanyName"] = checkIfExist.CompanyName; Session["PhoneNo"] = jObject.SelectToken("result.PhoneNo").Value(); Session["Amount"] = jObject.SelectToken("result.Amount").Value(); Session["BillDescription"] = jObject.SelectToken("result.SubServiceName").Value(); Session["Currency"] = jObject.SelectToken("result.Currency").Value(); Session["ExpireDate"] = jObject.SelectToken("result.ExpireDate").Value(); Session["PrintedDate"] = DateTime.Now.ToString("dd-MM-yyyy"); return RedirectToAction("DisplayInvoice", "NewCOI"); } if (checkresult == "Failure") { var Reslt = jObject.GetValue("message").ToString(); ViewData["Notfound"] = Reslt.ToString(); return View("NotFoundApp"); } return View("NotFoundApp"); } } public async Task DisplayPDFTransfer() { var ProjectCode = Session["ProjectCode"].ToString(); var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode); var InvoiceID = checkIfExist.InvoiceID; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage responseMessage = await client.GetAsync("http://192.168.2.31:8090/tic/invoice-gen/" + InvoiceID); var responseJson = await responseMessage.Content.ReadAsStringAsync(); var jObject = JObject.Parse(responseJson); var checkresult = jObject.GetValue("resultcode").ToString(); if (checkresult == "0") { Session["ControlNo"] = jObject.SelectToken("result.ControlNo").Value(); Session["QRCode"] = jObject.SelectToken("result.QRCode").Value(); Session["SubServiceName"] = jObject.SelectToken("result.SubServiceName").Value(); Session["FullName"] = jObject.SelectToken("result.FullName").Value(); Session["PhoneNo"] = jObject.SelectToken("result.PhoneNo").Value(); Session["Amount"] = jObject.SelectToken("result.Amount").Value(); Session["BillDescription"] = jObject.SelectToken("result.SubServiceName").Value(); Session["Currency"] = jObject.SelectToken("result.Currency").Value(); Session["ExpireDate"] = jObject.SelectToken("result.ExpireDate").Value(); Session["PrintedDate"] = DateTime.Now.ToString("dd-MM-yyyy"); return RedirectToAction("DisplayInvoiceTransfer", "NewCOI"); } if (checkresult == "Failure") { var Reslt = jObject.GetValue("message").ToString(); ViewData["Notfound"] = Reslt.ToString(); return View("NotFoundApp"); } return View("NotFoundApp"); } } } }