Mike Phares 83789cdd91 Added ControllerExtensions to be used instead of HtmlViewRenderer for net8
Added HttpException class for missing HttpException for net8

Wrapped HttpContext.Session, GetJsonResult, IsAjaxRequest and GetUserIdentityName in controllers for net8

Added AuthenticationService to test Fab2ApprovalMKLink code for net8

Compile conditionally flags to debug in dotnet core
2025-05-19 13:29:54 -07:00

1486 lines
71 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
#if !NET8
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using System.Threading;
using Fab2ApprovalSystem.PdfGenerator;
#endif
#if NET8
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
#endif
#if NET8
using Fab2ApprovalSystem.Extensions;
#endif
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Misc;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.ViewModels;
#if !NET8
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
#endif
namespace Fab2ApprovalSystem.Controllers;
[Authorize]
#if !NET8
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
[SessionExpireFilter]
public class LotTravelerController : PdfViewController {
#endif
#if NET8
[Route("[controller]")]
public class LotTravelerController : Controller {
#endif
private readonly LotTravelerDMO LotTravDMO = new();
private readonly string docTypeString = "LotTraveler";
private readonly WorkflowDMO wfDMO = new();
private readonly AppSettings? _AppSettings = GlobalVars.AppSettings;
public ActionResult CreateWorkRequest() {
LTWorkRequest workRequest = new();
try {
workRequest.OriginatorID = GlobalVars.GetUserId(GetSession());
LotTravDMO.InsertWorkRequest(workRequest);
return RedirectToAction("Edit", new { issueID = workRequest.ID });
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequest.SWRNumber.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n CreateWorkRequest - LotTraveler\r\n" + e.InnerException == null ? e.Message : e.InnerException.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = workRequest.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "CreateWorkRequest - " + exceptionString });
throw new Exception(e.Message);
}
}
public ActionResult Edit(int issueID) {
int isITARCompliant = 1;
GlobalVars.SetCreateNewRevision(GetSession(), false);
ViewBag.NewRevision = "false";
LTWorkRequest workRequest = new();
try {
workRequest = LotTravDMO.GetLTWorkRequestItemForRead(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
if (isITARCompliant == 0) // not ITAR Compliant
{
return View("UnAuthorizedAccess");
}
if (GlobalVars.GetUserId(GetSession()) == workRequest.OriginatorID)
ViewBag.IsOriginator = "true";
else
ViewBag.IsOriginator = "false";
List<ApproversListViewModel> userList = MiscDMO.GetPendingApproversListByDocument(issueID, workRequest.CurrentStep, (int)GlobalVars.DocumentType.LotTraveler);
ApproversListViewModel approver = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == GlobalVars.GetUserId(GetSession()); });
if (approver == null)
ViewBag.IsApprover = "false";
else
ViewBag.IsApprover = "true";
if (workRequest.CloseDate != null) {
// LATER ON SHOULD CALL THE LOT TRAVLELER VIEW
return RedirectToAction("WorkRequestReadOnly", new { issueID = issueID });
}
// open the view based on the Workflow step
if (workRequest.CurrentStep == 0) {
if ((workRequest.RecordLockIndicator && workRequest.RecordLockedBy != GlobalVars.GetUserId(GetSession()))) {
return RedirectToAction("WorkRequestReadOnly", new { issueID = issueID });
}
} else if (workRequest.CurrentStep >= 1 && workRequest.CurrentStep < 3 && workRequest.CloseDate == null) // Before
{
if ((ViewBag.IsApprover == "true") || (GlobalVars.IsAdmin(GetSession())))
return RedirectToAction("WorkRequestApproval", new { issueID = issueID });
else
return RedirectToAction("WorkRequestReadOnly", new { issueID = issueID });
} else if (workRequest.CurrentStep == 3) {
if ((workRequest.RecordLockIndicator && workRequest.RecordLockedBy != GlobalVars.GetUserId(GetSession())) || (ViewBag.IsApprover == "false")) {
return RedirectToAction("WorkRequestReadOnly", new { issueID = issueID });
} else {
GlobalVars.SetCreateNewRevision(GetSession(), true);
ViewBag.NewRevision = "true";
workRequest = LotTravDMO.GetLTWorkRequestItem(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
return RedirectToAction("WorkRequestRevision", new { workRequestID = issueID });
}
// Start the versioning of the documents with the Edit Feature
// Call the Edit Form
}
workRequest = LotTravDMO.GetLTWorkRequestItem(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
// else do this part
ViewBag.Departments = MiscDMO.GetDepartments();
ViewBag.AffectedModules = MiscDMO.GetModules();
ViewBag.WorkReqRevisionList = LotTravDMO.GetWorkReqRevisions(workRequest.SWRNumber);
return View(workRequest);
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequest.SWRNumber.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Edit WorkRequest - LotTraveler\r\n" + e.InnerException == null ? e.Message : e.InnerException.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = workRequest.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Edit WorkRequest - " + exceptionString });
throw new Exception(e.Message);
}
}
public ActionResult SaveRevision(LTWorkRequest model) {
try {
var data = model;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
ViewBag.NewRevision = "false";
GlobalVars.SetCreateNewRevision(GetSession(), false);
model.OriginatorID = GlobalVars.GetUserId(GetSession());
int newRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newRequestID);
return Content(newRequestID.ToString());
} else {
LotTravDMO.UpdateWorkRequest(model, GlobalVars.GetUserId(GetSession()));
return Content("");
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + model.SWRNumber.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n SaveRevision - LotTraveler\r\n" + e.InnerException == null ? e.Message : e.InnerException.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = model.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "SaveRevision - " + exceptionString });
throw new Exception(e.Message);
}
}
public ActionResult WorkRequestReadOnly(int issueID) {
int isITARCompliant = 1;
LTWorkRequest workRequest = new();
try {
workRequest = LotTravDMO.GetLTWorkRequestItemForRead(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
ViewBag.Departments = MiscDMO.GetDepartments();
ViewBag.AffectedModules = MiscDMO.GetModules();
ViewBag.WorkReqRevisionList = LotTravDMO.GetWorkReqRevisions(workRequest.SWRNumber);
return View(workRequest);
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + issueID.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n WorkRequestReadOnly - LotTraveler\r\n" + e.InnerException == null ? e.Message : e.InnerException.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "WorkRequestReadOnly - " + exceptionString });
throw new Exception(e.Message);
}
}
public ActionResult WorkRequestApproval(int issueID) {
int isITARCompliant = 1;
LTWorkRequest workRequest = new();
try {
workRequest = LotTravDMO.GetLTWorkRequestItemForRead(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
List<ApproversListViewModel> userList = MiscDMO.GetPendingApproversListByDocument(issueID, workRequest.CurrentStep, (int)GlobalVars.DocumentType.LotTraveler);
ApproversListViewModel approver = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == GlobalVars.GetUserId(GetSession()); });
if (approver == null)
ViewBag.IsApprover = "false";
else
ViewBag.IsApprover = "true";
if (workRequest.RecordLockIndicator && workRequest.RecordLockedBy != GlobalVars.GetUserId(GetSession())) {
return RedirectToAction("WorkRequestReadOnly", new { issueID = issueID });
}
workRequest = LotTravDMO.GetLTWorkRequestItem(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
ViewBag.Departments = MiscDMO.GetDepartments();
ViewBag.AffectedModules = MiscDMO.GetModules();
ViewBag.WorkReqRevisionList = LotTravDMO.GetWorkReqRevisions(workRequest.SWRNumber);
return View(workRequest);
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + issueID.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n WorkRequestApproval - LotTraveler\r\n" + e.InnerException == null ? e.Message : e.InnerException.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "WorkRequestApproval - " + exceptionString });
throw new Exception(e.Message);
}
}
public ActionResult GetWorkRequestRevision(int workRequestID) {
int isITARCompliant = 1;
LTWorkRequest workRequest = new();
workRequest = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
return Content("");
}
public ActionResult DisplayWorkRequestPDF(int workRequestID) {
WorkRequestPdf workRequest = new();
try {
workRequest = LotTravDMO.GetLTWorkRequestItemPDF(workRequestID);
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
// requires the controller to be inherited from MyController instead of MVC's Controller.
#if !NET8
return ViewPdf("", "WorkRequestPDF", workRequest);
#endif
#if NET8
if (Debugger.IsAttached)
return Content(this.RenderViewToString("WorkRequestPDF", workRequest), "text/html");
else
return this.GetBinaryContentResult("WorkRequestPDF", "application/pdf", workRequest);
#endif
} catch (Exception ex) {
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n DisplayWorkRequestPDF - LotTraveler\r\n" + ex.InnerException.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = workRequest.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "LotTravler", OperationType = "Generate PDF", Comments = ex.Message });
workRequest = null;
return Content("");
}
}
public ActionResult WorkRequestRevision(int workRequestID) {
int isITARCompliant = 1;
LTWorkRequest workRequest = new();
workRequest = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
List<ApproversListViewModel> userList = MiscDMO.GetPendingApproversListByDocument(workRequestID, workRequest.CurrentStep, (int)GlobalVars.DocumentType.LotTraveler);
ApproversListViewModel approver = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == GlobalVars.GetUserId(GetSession()); });
if (approver == null)
ViewBag.IsApprover = "false";
else
ViewBag.IsApprover = "true";
if (
(workRequest.RecordLockIndicator && workRequest.RecordLockedBy != GlobalVars.GetUserId(GetSession())
|| (ViewBag.IsApprover == "false"))
|| (!workRequest.IsCurrentRevision)
|| (workRequest.CloseDate != null)
) {
return RedirectToAction("WorkRequestReadOnly", new { issueID = workRequestID });
}
workRequest = LotTravDMO.GetLTWorkRequestItem(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
ViewBag.Departments = MiscDMO.GetDepartments();
ViewBag.AffectedModules = MiscDMO.GetModules();
ViewBag.WorkReqRevisionList = LotTravDMO.GetWorkReqRevisions(workRequest.SWRNumber);
return View(workRequest);
}
[HttpPost]
public ActionResult Edit(LTWorkRequest model) {
try {
GlobalVars.SetCreateNewRevision(GetSession(), false);
var data = model;
LotTravDMO.UpdateWorkRequest(model, GlobalVars.GetUserId(GetSession()));
} catch (Exception ex) {
return Content(ex.Message);
}
return Content("Successfully Saved");
}
/// <summary>
///
/// </summary>
public JsonResult GetBaseFlowLocations(string baseFlow) {
List<BaseFlowLocation> loclist = LotTravDMO.GetBaseFlowLocations(baseFlow);
return GetJsonResult(loclist);
}
public JsonResult GetMaterialRecord(int materialID) {
LTMaterial ltMaterial = LotTravDMO.GetMaterialRecord(materialID);
return GetJsonResult(ltMaterial);
}
public JsonResult GetBaseFlowOperations(string baseFlow, string location) {
List<BaseFlowOperations> operationslist = LotTravDMO.GetBaseFlowOperations(baseFlow, location);
return GetJsonResult(operationslist);
}
#if !NET8
public ActionResult GetMaterialDetails([DataSourceRequest] DataSourceRequest request, int workRequestID) {
return Json(LotTravDMO.GetMaterialDetails(workRequestID).ToDataSourceResult(request));
}
#endif
public JsonResult GetPartNumbers() {
List<PartNumberAttrib> operationslist = LotTravDMO.GetPartNumbers();
return GetJsonResult(operationslist);
}
#if !NET8
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InsertMaterialDetail([DataSourceRequest] DataSourceRequest request, LTMaterialViewModel model) {
try {
bool s = GlobalVars.GetCreateNewRevision(GetSession());
if (model != null && ModelState.IsValid) {
LotTravDMO.InsertMaterialDetail(model, GlobalVars.GetUserId(GetSession()));
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
} catch (Exception ex) {
return this.Json(new DataSourceResult {
Errors = ex.Message
});
}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateMaterialDetail([DataSourceRequest] DataSourceRequest request, LTMaterialViewModel model) {
try {
if (model != null && ModelState.IsValid) {
LotTravDMO.UpdateMaterialDetail(model, GlobalVars.GetUserId(GetSession()));
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
} catch (Exception ex) {
return this.Json(new DataSourceResult {
Errors = ex.Message
});
}
}
#endif
public ActionResult AddMaterialDetailRevision(LTWorkRequest model) {
var modelMaterialDetail = model.LTMaterial;
int previousMaterialID = model.LTMaterial.ID;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
modelMaterialDetail.LTWorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.InsertMaterialDetail(modelMaterialDetail, GlobalVars.GetUserId(GetSession()));
// TODO
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (modelMaterialDetail != null && ModelState.IsValid) {
LotTravDMO.InsertMaterialDetail(modelMaterialDetail, GlobalVars.GetUserId(GetSession()));
}
}
return Content(newWorkRequestID.ToString());
}
/// <summary>
/// For the Revison
/// </summary>
public ActionResult UpdateMaterialDetailRevision(LTWorkRequest model) {
var modelMaterialDetail = model.LTMaterial;
int previousMaterialID = model.LTMaterial.ID;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
modelMaterialDetail.LTWorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.UpdateMaterialDetailRevision(modelMaterialDetail, previousMaterialID);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (modelMaterialDetail != null && ModelState.IsValid) {
LotTravDMO.UpdateMaterialDetail(modelMaterialDetail, GlobalVars.GetUserId(GetSession()));
}
}
return Content(newWorkRequestID.ToString());
}
#if !NET8
public ActionResult DeleteMaterialDetail([DataSourceRequest] DataSourceRequest request, LTMaterialViewModel model) {
try {
if (model != null && ModelState.IsValid) {
LotTravDMO.DeleteMaterialDetail(model.ID);
}
} catch (Exception e) {
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
#endif
public ActionResult DeleteMaterialDetailRevision(LTWorkRequest model) {
var modelMaterialDetail = model.LTMaterial;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
modelMaterialDetail.LTWorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.DeleteMaterialDetailRevision(modelMaterialDetail.ID);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (modelMaterialDetail != null && ModelState.IsValid) {
LotTravDMO.DeleteMaterialDetail(modelMaterialDetail.ID);
}
}
return Content(newWorkRequestID.ToString());
}
#if !NET8
public ActionResult GetHoldSteps([DataSourceRequest] DataSourceRequest request, int workRequestID) {
return Json(LotTravDMO.GetHoldSteps(workRequestID).ToDataSourceResult(request));
}
public ActionResult InsertHoldStep([DataSourceRequest] DataSourceRequest request, LTHoldStep model) {
if (model != null && ModelState.IsValid) {
model.UpdatedBy = GlobalVars.GetUserId(GetSession());
LotTravDMO.InsertHoldStep(model);
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
#endif
public ActionResult UpdateHoldStepRevision(LTWorkRequest model) {
var holdStepModel = model.LTHoldStep;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
holdStepModel.LTWorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.UpdateHoldStepRevision(holdStepModel);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (holdStepModel != null && ModelState.IsValid) {
holdStepModel.UpdatedBy = GlobalVars.GetUserId(GetSession());
LotTravDMO.UpdateHoldStep(holdStepModel);
}
}
return Content(newWorkRequestID.ToString());
}
public ActionResult InsertHoldStepRevision(LTWorkRequest model) {
var holdStepModel = model.LTHoldStep;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
holdStepModel.LTWorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.InsertHoldStepRevision(holdStepModel);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (holdStepModel != null && ModelState.IsValid) {
holdStepModel.UpdatedBy = GlobalVars.GetUserId(GetSession());
LotTravDMO.InsertHoldStep(holdStepModel);
}
}
return Content(newWorkRequestID.ToString());
}
public ActionResult DeleteHoldStepRevision(LTWorkRequest model) {
var holdStepModel = model.LTHoldStep;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
holdStepModel.LTWorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.DeleteHoldStepRevision(holdStepModel.ID);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (holdStepModel != null && ModelState.IsValid) {
LotTravDMO.DeleteHoldStep(holdStepModel.ID, GlobalVars.GetUserId(GetSession()));
}
}
return Content(newWorkRequestID.ToString());
}
public void UpdateHoldStep(LTHoldStep model) {
if (model != null && ModelState.IsValid) {
LotTravDMO.UpdateHoldStep(model);
}
}
#if !NET8
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteHoldStep([DataSourceRequest] DataSourceRequest request, LTHoldStep model) {
try {
if (model != null && ModelState.IsValid) {
LotTravDMO.DeleteHoldStep(model.ID, GlobalVars.GetUserId(GetSession()));
}
} catch (Exception ex) {
return this.Json(new DataSourceResult {
Errors = ex.Message
});
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
#endif
public ActionResult GetHoldStep(int holdStepID) {
LTHoldStep model = new();
model = LotTravDMO.GetHoldStep(holdStepID);
return PartialView("_HoldStepAttachments", model);
}
public ActionResult GetHoldStepRevision(int holdStepID) {
LTHoldStep model = new();
model = LotTravDMO.GetHoldStep(holdStepID);
return PartialView("_HoldStepAttachmentsRevision", model);
}
public ActionResult GetLotTravHoldStepRevision(int ltHoldStepID) {
LTLotTravelerHoldSteps model = new();
model = LotTravDMO.GetLotTravHoldStep(ltHoldStepID);
return PartialView("_LotTravHoldStepAttachRev", model);
}
#if !NET8
public ActionResult GetHoldStepAttachments([DataSourceRequest] DataSourceRequest request, int holdStepID) {
return Json(LotTravDMO.GetHoldStepAttachemnts(holdStepID).ToDataSourceResult(request));
}
public ActionResult GetLTHoldStepAttachments([DataSourceRequest] DataSourceRequest request, int ltHoldStepID) {
return Json(LotTravDMO.GetLotTravHoldStepAttachemnts(ltHoldStepID).ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteHoldStepAttachment([DataSourceRequest] DataSourceRequest request, LTWorkRequestAttachment model) {
try {
if (model != null && ModelState.IsValid) {
LotTravDMO.DeleteWorkRequestAttachment(model.ID);
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Delete =" + model.ID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n AttachmentID Work Request\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { UserID = GetUserIdentityName(), OperationType = "Error", Comments = exceptionString });
throw new Exception(e.Message);
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
public ActionResult GetWorkRequestAttachments([DataSourceRequest] DataSourceRequest request, int workRequestID) {
return Json(LotTravDMO.GetWorkRequestAttachments(workRequestID).ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateWorkRequestAttachment([DataSourceRequest] DataSourceRequest request, LTWorkRequestAttachment model) {
if (model != null && ModelState.IsValid) {
LotTravDMO.UpdateWorkRequestAttachment(model);
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
#endif
public ActionResult UpdateWorkRequestAttachmentRevision(LTWorkRequest model) {
var wrAttachmentDetail = model.WorkRequestAttachment;
int previousWorkRequestAttachmentID = model.WorkRequestAttachment.ID;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
wrAttachmentDetail.WorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.UpdateWorkRequestAttachmentRevision(wrAttachmentDetail, previousWorkRequestAttachmentID);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (wrAttachmentDetail != null && ModelState.IsValid) {
LotTravDMO.UpdateWorkRequestAttachment(wrAttachmentDetail);
}
}
return Content(newWorkRequestID.ToString());
}
#if !NET8
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DeleteWorkRequestAttachment([DataSourceRequest] DataSourceRequest request, LTWorkRequestAttachment model) {
try {
if (model != null && ModelState.IsValid) {
LotTravDMO.DeleteWorkRequestAttachment(model.ID);
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Delete =" + model.ID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n AttachmentID WorkRequiest\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { UserID = GetUserIdentityName(), OperationType = "Error", Comments = exceptionString });
throw new Exception(e.Message);
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
#endif
public ActionResult DeleteWorkRequestAttachmentRevision(LTWorkRequest model) {
var wrAttachmentDetail = model.WorkRequestAttachment;
int previousWorkRequestAttachmentID = model.WorkRequestAttachment.ID;
int newWorkRequestID = model.ID;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
wrAttachmentDetail.WorkRequestID = newWorkRequestID;
// Any update will be a new entry
LotTravDMO.DeleteWorkRequestAttachmentRevision(wrAttachmentDetail.ID);
// TODO
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
} else {
if (wrAttachmentDetail != null && ModelState.IsValid) {
LotTravDMO.DeleteWorkRequestAttachment(wrAttachmentDetail.ID);
}
}
return Content(newWorkRequestID.ToString());
}
#if !NET8
public ActionResult AttachSaveWorkRequest(IEnumerable<HttpPostedFileBase> files, int workRequestID, int currentRevision, int swrNo, string comments, string docType) {
// The Name of the Upload component is "files"
if (files != null) {
int userId = GlobalVars.GetUserId(GetSession());
foreach (var file in files) {
LotTravelerHelper.AttachSaveWorkRequest(_AppSettings, LotTravDMO, workRequestID, swrNo, comments, docType, userId, file.FileName, file.InputStream);
}
}
return Content("");
}
public ActionResult AttachSaveWorkRequestRevision(IEnumerable<HttpPostedFileBase> files, int workRequestID, int currentRevision, int swrNo, string revComments, string docType, string attachComments) {
bool newRevision = false;
int newWorkRequestID = -1;
int isITARCompliant = 1;
LTWorkRequest model = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
model.RevisionComments = revComments;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
newRevision = true;
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
// Send email to the Originator and Group of People
NotifyfWorkRequestRevisionChange(newWorkRequestID);
}
// The Name of the Upload component is "files"
if (files != null) {
int userId = GlobalVars.GetUserId(GetSession());
foreach (var file in files) {
LotTravelerHelper.AttachSaveWorkRequestRevision(_AppSettings, LotTravDMO, workRequestID, swrNo, docType, attachComments, newRevision, userId, file.FileName, file.InputStream);
}
}
return Content("");
}
public ActionResult HoldStepAttachSave(IEnumerable<HttpPostedFileBase> HoldStepAttachment, int holdStepID, int currentRevision, int swrNo, string docType, string comments) {
// The Name of the Upload component is "files"
try {
if (HoldStepAttachment != null) {
int userId = GlobalVars.GetUserId(GetSession());
foreach (var file in HoldStepAttachment) {
LotTravelerHelper.HoldStepAttachSave(_AppSettings, LotTravDMO, holdStepID, swrNo, docType, comments, userId, file.FileName, file.InputStream);
}
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "HoldStep=" + holdStepID.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = holdStepID, UserID = GetUserIdentityName(), DocumentType = docTypeString, OperationType = "Error", Comments = "HoldStep Attachment - " + exceptionString });
throw new Exception(e.Message);
}
return Content("");
}
public ActionResult HoldStepAttachSaveRev(IEnumerable<HttpPostedFileBase> HoldStepAttachment, int workRequestID, int holdStepID, int currentRevision, int swrNo, string docType, string comments, string revComments) {
// The Name of the Upload component is "files"
bool newRevision = false;
int newWorkRequestID = -1;
int isITARCompliant = 1;
LTWorkRequest model = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
model.RevisionComments = revComments;
if (GlobalVars.GetCreateNewRevision(GetSession())) {
newRevision = true;
GlobalVars.SetCreateNewRevision(GetSession(), false);
newWorkRequestID = LotTravDMO.CreateWorkRequestRevision(model, GlobalVars.GetUserId(GetSession()));
NotifyfWorkRequestRevisionChange(newWorkRequestID);
}
try {
if (HoldStepAttachment != null) {
int userId = GlobalVars.GetUserId(GetSession());
foreach (var file in HoldStepAttachment) {
LotTravelerHelper.HoldStepAttachSaveRev(_AppSettings, LotTravDMO, holdStepID, swrNo, docType, comments, newRevision, userId, file.FileName, file.InputStream);
}
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "HoldStep=" + holdStepID.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = holdStepID, UserID = GetUserIdentityName(), DocumentType = docTypeString, OperationType = "Error", Comments = "HoldStep Attachment - " + exceptionString });
throw new Exception(e.Message);
}
return Content("");
}
#endif
public int GetRevisedWrkReqIDFromHoldStepID(int prevHoldStepID) {
return LotTravDMO.GetRevisedWrkReqIDFromHoldStepID(prevHoldStepID);
}
public int GetRevisedWrkReqIDFromPreviousWrkReqID(int prevWorkRequestID) {
return LotTravDMO.GetRevisedWrkReqIDFromPreviousWrkReqID(prevWorkRequestID);
}
public JsonResult GetWorkRequestAttachDetail(int wrAttachmentID) {
LTWorkRequestAttachment data = LotTravDMO.GetWorkRequestAttachDetail(wrAttachmentID);
return GetJsonResult(data);
}
public ActionResult SubmitDocument(int workRequestID, int documentType) {
int isITARCompliant = 1;
LTWorkRequest ltWR = new();
try {
int appoverCount = LotTravDMO.SubmitDocument(workRequestID, GlobalVars.GetUserId(GetSession()), documentType, out isITARCompliant);
if (isITARCompliant == 0) // not ITAR Compliant
{
return View("UnAuthorizedAccess");
} else {
if (appoverCount > 0) {
NotifyApprovers(workRequestID, (byte)GlobalVars.WorkFLowStepNumber.Step1, documentType);
} else {
// automaically approve current step (Step 1) beacuase there are no approvers in step 1 and move to the next step of approval
Approve(workRequestID, (byte)GlobalVars.WorkFLowStepNumber.Step1, "", documentType); // this is the Submit Level Approval
}
ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
List<ApproversListViewModel> userList = MiscDMO.GetPendingApproversListByDocument(workRequestID, ltWR.CurrentStep, documentType);
ApproversListViewModel approver = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == GlobalVars.GetUserId(GetSession()); });
if (approver == null)
ViewBag.IsApprover = "false";
else
ViewBag.IsApprover = "true";
if (GlobalVars.GetUserId(GetSession()) == ltWR.OriginatorID)
ViewBag.IsOriginator = "true";
else
ViewBag.IsOriginator = "false";
if (IsAjaxRequest()) {
return Content("Redirect");
} else {
return Content("Invalid");
}
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequestID.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n SubmitDocument\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = docTypeString, OperationType = "Error", Comments = "SubmitDocument - " + exceptionString });
throw new Exception(e.Message);
}
}
public void Approve(int workRequestID, byte currentStep, string comments, int documentType) {
LTWorkRequest ltWR = new();
int isITAR = 1;
ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITAR, GlobalVars.GetUserId(GetSession()));
try {
bool lastStep = false;
bool lastApprover = wfDMO.Approve(_AppSettings, workRequestID, currentStep, comments, out lastStep, GlobalVars.GetUserId(GetSession()), documentType, ltWR.WorkFlowNumber);
while (lastApprover && !lastStep) {
currentStep++;
lastApprover = wfDMO.Approve(_AppSettings, workRequestID, currentStep, comments, out lastStep, GlobalVars.GetUserId(GetSession()), documentType, ltWR.WorkFlowNumber);
NotifyApprovers(workRequestID, currentStep, documentType);
}
if (lastApprover && lastStep) {
// Send email to the Originator and different groups
NotifyApprovalOfWorkRequest(workRequestID);
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequestID.ToString() + " Step:" + currentStep + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Approve - " + exceptionString });
throw new Exception(e.Message);
}
}
public void Reject(int workRequestID, byte currentStep, string comments, int docType) {
LTWorkRequest ltWR = new();
int isITARCompliant = 1;
ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
try {
if (GlobalVars.IsUserIdValueNotNull(GetSession())) {
wfDMO.Reject(workRequestID, currentStep, comments, GlobalVars.GetUserId(GetSession()), docType);
NotifyRejectionToOrginator(workRequestID);
} else {
Response.Redirect("~/Account/Login");
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequestID.ToString() + " Step:" + currentStep + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Reject\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Reject - " + exceptionString });
throw new Exception(e.Message);
}
}
public void NotifyRejectionToOrginator(int workRequestID) {
int isITARCompliant = 0;
string username = GlobalVars.GetUserName(GetSession());
List<string> emailIst = LotTravDMO.GetRejectionOrginatorEmailList(workRequestID).Distinct().ToList();
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
string userEmail = LotTravelerHelper.NotifyRejectionToOrginator(_AppSettings, GetUserIdentityName(), workRequestID, username, emailIst, ltWR);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "Rejection: " + userEmail });
} catch { }
}
public void NotifyApprovers(int workRequestID, byte currentStep, int documentType) {
string emailSentList = "";
int isITARCompliant = 0;
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(workRequestID, currentStep, documentType).Distinct().ToList();
emailSentList = LotTravelerHelper.NotifyApprovers(_AppSettings, GetUserIdentityName(), workRequestID, emailSentList, ltWR, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "Approvers for Step " + currentStep.ToString() + ":" + emailSentList });
} catch { }
}
public void NotifyApprovalOfWorkRequest(int workRequestID) {
string emailSentList = "";
int isITARCompliant = 0;
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
List<string> emailIst = MiscDMO.GetWorkRequestApprovedNotifyList((int)GlobalVars.NotificationType.WorkRequest, workRequestID, GlobalVars.GetUserId(GetSession())).Distinct().ToList();
emailSentList = LotTravelerHelper.NotifyApprovalOfWorkRequest(_AppSettings, GetUserIdentityName(), workRequestID, emailSentList, ltWR, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "Approvers for WorkRequest: " + emailSentList });
} catch { }
}
public void NotifyfWorkRequestRevisionChange(int workRequestID) {
string emailSentList = "";
int isITARCompliant = 0;
int currentUserID = GlobalVars.GetUserId(GetSession());
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, currentUserID);
List<string> emailIst = MiscDMO.GetWorkRequestRevisionNotifyList((int)GlobalVars.NotificationType.WorkRequest, workRequestID, currentUserID).Distinct().ToList();
emailSentList = LotTravelerHelper.NotifyfWorkRequestRevisionChange(_AppSettings, GetUserIdentityName(), workRequestID, emailSentList, ltWR, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "Work Request Revision Change for :" + emailSentList });
} catch { }
}
public void NotifyLotTravelerRevisionChange(int ltLotID, int revisionNumber) {
string emailSentList = "";
LTLotTravelerHeaderViewModel data = LotTravDMO.GetLotTravelerHeaderForReadOnly(ltLotID, revisionNumber);
int currentUserID = GlobalVars.GetUserId(GetSession());
List<string> emailIst = MiscDMO.GetLotTravelerCreationAndRevisionNotifyList(ltLotID, data.LTWorkRequestID, currentUserID).Distinct().ToList();
emailSentList = LotTravelerHelper.NotifyLotTravelerRevisionChange(_AppSettings, GetUserIdentityName(), emailSentList, data, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = data.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Email", Comments = "Lot Traveler Revision Change Notification:" + emailSentList });
} catch { }
}
public void NotifyLotTravelerCreation(int ltLotID, int revisionNumber) {
string emailSentList = "";
LTLotTravelerHeaderViewModel data = LotTravDMO.GetLotTravelerHeaderForReadOnly(ltLotID, revisionNumber);
int currentUserID = GlobalVars.GetUserId(GetSession());
List<string> emailIst = MiscDMO.GetLotTravelerCreationAndRevisionNotifyList(ltLotID, data.LTWorkRequestID, currentUserID).Distinct().ToList();
emailSentList = LotTravelerHelper.NotifyLotTravelerCreation(_AppSettings, GetUserIdentityName(), emailSentList, data, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = data.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Email", Comments = "Lot Traveler Revision Change Notification:" + emailSentList });
} catch { }
}
#if !NET8
public ActionResult GetApproversList([DataSourceRequest] DataSourceRequest request, int workRequestID, byte step) {
return Json(MiscDMO.GetApproversListByDocument(workRequestID, step, (int)GlobalVars.DocumentType.LotTraveler).ToDataSourceResult(request));
}
#endif
public void ReleaseLockOnDocument(int workRequestID) {
LotTravDMO.ReleaseLockOnDocument(GlobalVars.GetUserId(GetSession()), workRequestID);
}
public void ReleaseLockOnLotTravelerUpdateDoc(int lotID) {
try {
LotTravDMO.ReleaseLockOnLotTravelerUpdateDoc(GlobalVars.GetUserId(GetSession()), lotID);
} catch {
// TODO
// unlock the current revision of the Lot traveler
LotTravDMO.ReleaseLockOnLotTravelerUpdateDoc(-1, lotID);
}
}
public JsonResult GetAllUsersList() {
UserAccountDMO userDMO = new();
IEnumerable<LoginModel> userlist = userDMO.GetAllUsers();
return GetJsonResult(userlist);
}
public void ReAssignApproverByAdmin(int workRequestID, int reAssignApproverFrom, int reAssignApproverTo, byte step, int docType) {
var email = "";
int isITARCompliant = 0;
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
try {
email = wfDMO.ReAssignApproval(workRequestID, reAssignApproverFrom, reAssignApproverTo, step, docType);
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequestID.ToString() + " Step:" + step + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n ReAssignApproval\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Error", Comments = "ReAssignApproval - " + exceptionString });
throw new Exception(e.Message);
}
LotTravelerHelper.ReAssignApproverByAdmin(_AppSettings, GetUserIdentityName(), workRequestID, email, ltWR);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "ReAssign Approver: " + email });
} catch { }
}
public void ReAssignApproval(int workRequestID, int userIDs, byte step, int docType) {
var email = "";
int isITARCompliant = 0;
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
try {
email = wfDMO.ReAssignApproval(workRequestID, GlobalVars.GetUserId(GetSession()), userIDs, step, docType);
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequestID.ToString() + " Step:" + step + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n ReAssignApproval\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Error", Comments = "ReAssignApproval - " + exceptionString });
throw new Exception(e.Message);
}
LotTravelerHelper.ReAssignApproval(_AppSettings, GetUserIdentityName(), workRequestID, email, ltWR);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "ReAssign Approver: " + email });
} catch { }
}
public void AddAdditionalApproval(int workRequestID, byte step, string userIDs, int docType) {
string emailSentList = "";
var emailArray = "";
int isITARCompliant = 0;
LTWorkRequest ltWR = LotTravDMO.GetLTWorkRequestItemForRead(workRequestID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
try {
emailArray = wfDMO.AddAdditionalApproval(workRequestID, userIDs, step, docType);
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + workRequestID.ToString() + " Step:" + step + " " + " Userid:" + userIDs + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n AddAdditionalApproval\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Error", Comments = "AddAdditionalApproval - " + exceptionString });
throw new Exception(e.Message);
}
emailSentList = LotTravelerHelper.AddAdditionalApproval(_AppSettings, GetUserIdentityName(), workRequestID, emailSentList, emailArray, ltWR);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Email", Comments = "Additonal Approver: " + emailSentList });
} catch { }
}
public JsonResult AddLots(string lotNumbers, int workRequestID) {
IssueWithExistingLotsViewModel issueWEL = new();
try {
if (lotNumbers.Length > 0) {
string[] tempLots = lotNumbers.Split(new char[] { '~' });
foreach (string lotNumber in tempLots) {
LTLot l = new();
l.LotNumber = lotNumber;
l.WorkRequestID = workRequestID;
l.LotUploadedBy = GlobalVars.GetUserId(GetSession());
LotTravDMO.InsertLot(l);
if (l.WRWithExistingLot != 0) {
issueWEL.LotList += l.LotNumber + "~";
issueWEL.IssuesList += l.WRWithExistingLot.ToString() + "~";
}
}
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "IssueID=" + workRequestID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n AddLots Work Request\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { UserID = GetUserIdentityName(), DocumentType = "Work Request", OperationType = "Error", Comments = exceptionString });
throw new Exception(e.Message);
}
return GetJsonResult(issueWEL);
}
#if !NET8
public JsonResult SearchLots(string searchText, string searchBy) {
List<String> lotlist = MiscDMO.SearchLTLots(searchText, searchBy).Select(x => x.LotNumber).ToList<String>();
return GetJsonResult(lotlist);
}
public JsonResult SearchParts(string searchText) {
List<String> partList = MiscDMO.SearchLTParts(searchText.Trim()).Select(x => x.WIPPartData).ToList<String>();
return GetJsonResult(partList);
}
public ActionResult GetLotList([DataSourceRequest] DataSourceRequest request, int workRequestID) {
return Json(LotTravDMO.GetLotList(workRequestID).ToDataSourceResult(request));
}
#endif
public void CreateTaveler(int ltLotID, int workRequestID) {
try {
LotTravDMO.CreateTraveler(ltLotID, workRequestID, GlobalVars.GetUserId(GetSession()));
// Thread.Sleep(10000);
NotifyLotTravelerCreation(ltLotID, -1);
} catch (Exception ex) {
EventLogDMO.Add(new WinEventLog() { IssueID = workRequestID, UserID = GetUserIdentityName(), DocumentType = "LotTraveler", OperationType = "CreateTaveler", Comments = ex.Message });
throw new Exception(ex.Message);
}
}
#if !NET8
public JsonResult GetLotTravelerHeader(int ltLotID) {
LTLotTravelerHeaderViewModel data = new LTLotTravelerHeaderViewModel();
data = LotTravDMO.GetLotTravelerHeaderForUpdate(ltLotID, GlobalVars.GetUserId(GetSession()));
return GetJsonResult(data);
}
public ActionResult GetLotTravRevisions(int ltLotID) {
return GetJsonResult(LotTravDMO.GetLotTravRevisions(ltLotID));
}
#endif
public ActionResult DisplayLotTraveler(int ltLotID) {
LTLotTravelerHeaderViewModel data = new();
data = LotTravDMO.GetLotTravelerHeaderForUpdate(ltLotID, GlobalVars.GetUserId(GetSession()));
ViewBag.LotTravRevisionList = LotTravDMO.GetLotTravRevisions(ltLotID);
ViewBag.LotList = LotTravDMO.GetLotsWithTraveler(data.LTWorkRequestID);
if (data.RecordLockIndicator && data.RecordLockedBy != GlobalVars.GetUserId(GetSession())) {
// redirect to a readonly Lot Travler
return Content("Readonly" + "~" + data.LotTravCurrentRevision.ToString());
} else
return Content("Update");
}
public ActionResult LotTravelerUpdate(int ltLotID) {
LTLotTravelerHeaderViewModel data = new();
data = LotTravDMO.GetLotTravelerHeaderForUpdate(ltLotID, GlobalVars.GetUserId(GetSession()));
if (data.TravelerClosedDate != null) {
return RedirectToAction("LotTravelerReadOnly", new { ltLotID = ltLotID, revisionNumber = -1 });
}
ViewBag.LotTravRevisionList = LotTravDMO.GetLotTravRevisions(ltLotID);
ViewBag.LotList = LotTravDMO.GetLotsWithTraveler(data.LTWorkRequestID);
GlobalVars.SetCreateLotTravNewRevision(GetSession(), true);
return View(data);
}
public ActionResult LotTravelerReadonly(int ltLotID, int revisionNumber) {
LTLotTravelerHeaderViewModel data = new();
data = LotTravDMO.GetLotTravelerHeaderForReadOnly(ltLotID, revisionNumber);
if (data.IsCurrentRevision && (!data.RecordLockIndicator)) {
return RedirectToAction("LotTravelerUpdate", new { ltLotID = ltLotID });
}
ViewBag.LotTravRevisionList = LotTravDMO.GetLotTravRevisions(ltLotID);
ViewBag.LotList = LotTravDMO.GetLotsWithTraveler(data.LTWorkRequestID);
return View(data);
}
public ActionResult DisplayLotTravelerForExecute(int ltLotID) {
LTLotTravelerHeaderViewModel data = new();
data = LotTravDMO.GetLotTravelerHeaderForUpdate(ltLotID, GlobalVars.GetUserId(GetSession()));
ViewBag.LotTravRevisionList = LotTravDMO.GetLotTravRevisions(ltLotID);
ViewBag.LotList = LotTravDMO.GetLotsWithTraveler(data.LTWorkRequestID);
if (data.RecordLockIndicator && data.RecordLockedBy != GlobalVars.GetUserId(GetSession())) {
// redirect to a readonly Lot Travler
return Content("Readonly" + "~" + data.LotTravCurrentRevision.ToString());
} else
return Content("Execute");
}
public ActionResult LotTravelerExecute(int ltLotID) {
LTLotTravelerHeaderViewModel data = new();
data = LotTravDMO.GetLotTravelerHeaderForUpdate(ltLotID, GlobalVars.GetUserId(GetSession()));
ViewBag.LotTravRevisionList = LotTravDMO.GetLotTravRevisions(ltLotID);
ViewBag.LotList = LotTravDMO.GetLotsWithTraveler(data.LTWorkRequestID);
return View(data);
}
#if !NET8
public ActionResult GetLotTravHoldSteps([DataSourceRequest] DataSourceRequest request, int LotID) {
return Json(LotTravDMO.GetLotTravHoldSteps(LotID).ToDataSourceResult(request));
}
public ActionResult GetLotTravHoldStepsPending([DataSourceRequest] DataSourceRequest request, int LotID) {
return Json(LotTravDMO.GetLotTravHoldStepsPending(LotID).ToDataSourceResult(request));
}
public ActionResult GetLotTravHoldStepsCompleted([DataSourceRequest] DataSourceRequest request, int LotID) {
return Json(LotTravDMO.GetLotTravHoldStepsCompleted(LotID).ToDataSourceResult(request));
}
#endif
public void UpdateLotTravlerExecution(int currentHoldStepID, string taskComments, bool taskcompleted) {
LotTravDMO.UpdateLotTravlerExecution(currentHoldStepID, taskComments, taskcompleted, GlobalVars.GetUserId(GetSession()));
}
#if !NET8
public ActionResult GetLotTravHoldStepsByRevision([DataSourceRequest] DataSourceRequest request, int LotID, int revisionNumber) {
return Json(LotTravDMO.GetLotTravelerHolStepsByRevision(LotID, revisionNumber).ToDataSourceResult(request));
}
#endif
public ActionResult UpdateLotTravHoldStepRevision(LTLotTravelerHoldSteps ltHoldStepObj) {
int prevLotTravRevID = ltHoldStepObj.LotTravelerRevisionID;
int newLotTravRevID = 1;
try {
if (GlobalVars.GetCreateLotTravNewRevision(GetSession())) {
// Create a new Revision
GlobalVars.SetCreateLotTravNewRevision(GetSession(), false);
newLotTravRevID = LotTravDMO.CreateLotTravelerRevision(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
try {
LotTravDMO.UpdateRevisedLotTravelerHoldStep(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
} catch {
LotTravDMO.RestoreLotTravToPrevRevision(prevLotTravRevID, newLotTravRevID);
throw new Exception("There was a problem while creating the revision, Please try againm,. \n If the problem persist please contact the Site Administrator");
}
// send a notification
// - 1 indicates to return the current revision
NotifyLotTravelerRevisionChange(ltHoldStepObj.LTLotID, -1);
} else {
int result = LotTravDMO.UpdateLotTravelerHoldStep(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
if (result == -1) {
throw new Exception("Cannot add the Hold Step as the step has already been passed in the Mfg Process.");
}
}
} catch (Exception ex) {
return Content(ex.Message);
}
return Content(GlobalVars.SUCCESS);
}
public ActionResult InsertLotTravHoldStepRevision(LTLotTravelerHoldSteps ltHoldStepObj) {
int prevLotTravRevID = ltHoldStepObj.LotTravelerRevisionID;
int newLotTravRevID = -1;
try {
if (GlobalVars.GetCreateLotTravNewRevision(GetSession())) {
// Create a new Revision
GlobalVars.SetCreateLotTravNewRevision(GetSession(), false);
int result = LotTravDMO.CanAddLocationOperation(ltHoldStepObj);
if (result == -1) {
GlobalVars.SetCreateLotTravNewRevision(GetSession(), true);
throw new Exception("Cannot add the Hold Step as the step has already been passed in the Mfg Process.");
}
newLotTravRevID = LotTravDMO.CreateLotTravelerRevision(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
ltHoldStepObj.LotTravelerRevisionID = newLotTravRevID;
try {
LotTravDMO.InsertLotTravelerHoldStep(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
} catch {
// roll back the revision creation
LotTravDMO.RestoreLotTravToPrevRevision(prevLotTravRevID, newLotTravRevID);
throw new Exception("There was a problem while creating the revision, Please logout and log back and then retry. \n If the problem persist please contact the Site Administrator");
}
// send a notification
// - 1 indicates to return the current revision
NotifyLotTravelerRevisionChange(ltHoldStepObj.LTLotID, -1);
} else {
int result = LotTravDMO.InsertLotTravelerHoldStep(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
if (result == -1) {
throw new Exception("Cannot add the Hold Step as the step has already been passed in the Mfg Process.");
}
}
} catch (Exception ex) {
return Content(ex.Message);
}
return Content(GlobalVars.SUCCESS);
}
public ActionResult DeleteLotTravHoldStepRevision(LTLotTravelerHoldSteps ltHoldStepObj) {
int prevLotTravRevID = ltHoldStepObj.LotTravelerRevisionID;
int newLotTravRevID = -1;
try {
if (GlobalVars.GetCreateLotTravNewRevision(GetSession())) {
// Create a new Revision
GlobalVars.SetCreateLotTravNewRevision(GetSession(), false);
newLotTravRevID = LotTravDMO.CreateLotTravelerRevision(ltHoldStepObj, GlobalVars.GetUserId(GetSession()));
try {
LotTravDMO.DeleteLotTravHoldStepRevision(ltHoldStepObj.ID);
} catch {
// roll back the revision creation
LotTravDMO.RestoreLotTravToPrevRevision(prevLotTravRevID, newLotTravRevID);
throw new Exception("There was a problem while creating the revision, Please logout and log back and then retry. \n If the problem persist please contact the Site Administrator");
}
// send a notification
// - 1 indicates to return the current revision
NotifyLotTravelerRevisionChange(ltHoldStepObj.LTLotID, -1);
} else {
LotTravDMO.DeleteLotTravHoldStep(ltHoldStepObj.ID);
}
} catch (Exception ex) {
return Content(ex.Message);
}
return Content(GlobalVars.SUCCESS);
}
public void DeleteLot(int ltLotID) {
LotTravDMO.DeleteLot(ltLotID);
}
public ActionResult DisplayLotTravlerPdf(int ltLotID, int revisionNumber) {
LotTravelerPdf traveler = new();
try {
traveler = LotTravDMO.GetLotTravlerPdf(ltLotID, revisionNumber);
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
// requires the controller to be inherited from MyController instead of MVC's Controller.
#if !NET8
return ViewPdf("", "LotTravelerPDF", traveler);
#endif
#if NET8
if (Debugger.IsAttached)
return Content(this.RenderViewToString("LotTravelerPDF", traveler), "text/html");
else
return this.GetBinaryContentResult("LotTravelerPDF", "application/pdf", traveler);
#endif
} catch (Exception ex) {
EventLogDMO.Add(new WinEventLog() { IssueID = traveler.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "LotTraveler", OperationType = "Generate PDF", Comments = ex.Message });
traveler = null;
return Content("");
}
}
#if !NET8
public ActionResult ApprovalLogHistory_Read([DataSourceRequest] DataSourceRequest request, int swrNumber) {
return GetJsonResult(LotTravDMO.GetWorkReqApprovalLogHistory(swrNumber).ToDataSourceResult(request));
}
public ActionResult GetWorkRequestRevisionHistory([DataSourceRequest] DataSourceRequest request, int swrNumber) {
return GetJsonResult(LotTravDMO.GetWorkReqRevisionHistory(swrNumber).ToDataSourceResult(request));
}
public ActionResult GetLotTravelerRevisionHistory([DataSourceRequest] DataSourceRequest request, int lotID) {
return GetJsonResult(LotTravDMO.GetLotTravelerRevisionHistory(lotID).ToDataSourceResult(request));
}
public ActionResult LotTravHoldStepAttachSaveRev(IEnumerable<HttpPostedFileBase> LotTravHoldStepAttachment, int ltHoldStepID, int swrNo, string docType, string revComments) {
// The Name of the Upload component is "files"
int prevLotTravRevID = -1;
int newLotTravRevID = -1;
bool newRevision = false;
LTLotTravelerHoldSteps model = LotTravDMO.GetLotTravHoldStep(ltHoldStepID);
prevLotTravRevID = model.LotTravelerRevisionID;
model.RevisionComments = revComments;
if (GlobalVars.GetCreateLotTravNewRevision(GetSession())) {
// Create a new Revision
newRevision = true;
GlobalVars.SetCreateLotTravNewRevision(GetSession(), false);
newLotTravRevID = LotTravDMO.CreateLotTravelerRevision(model, GlobalVars.GetUserId(GetSession()));
model.LotTravelerRevisionID = newLotTravRevID;
}
try {
if (LotTravHoldStepAttachment != null) {
int userId = GlobalVars.GetUserId(GetSession());
foreach (var file in LotTravHoldStepAttachment) {
LotTravelerHelper.LotTravHoldStepAttachSaveRev(_AppSettings, LotTravDMO, ltHoldStepID, swrNo, docType, prevLotTravRevID, newLotTravRevID, newRevision, userId, file.FileName, file.InputStream);
}
// send a notification
// - 1 indicates to return the current revision
if (newRevision) {
NotifyLotTravelerRevisionChange(model.LTLotID, -1);
}
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "LotTravHoldStep=" + ltHoldStepID.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Attachment \r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ltHoldStepID, UserID = GetUserIdentityName(), DocumentType = docTypeString, OperationType = "Error", Comments = "Lot Traveler HoldStep Attachment - " + exceptionString });
throw new Exception(e.Message);
}
return Content("");
}
#endif
public bool IsWorkRequestDocLockedByUser(int workRequestID) {
int result = LotTravDMO.IsWorkRequestDocLockedByUser(workRequestID, GlobalVars.GetUserId(GetSession()));
if (result == 0)
return false;
else
return true;
}
public ActionResult CloseTraveler(int ltLotID, string reason) {
int result = LotTravDMO.CloseTraveler(ltLotID, GlobalVars.GetUserId(GetSession()), reason);
if (result == 1)
return Content("C");
else
return Content("O");
}
public FileResult DownloadFile(string fileGuid, string swrNumber, int typeOfDoc) {
string fileName = LotTravDMO.GetFileName(fileGuid, typeOfDoc);
string fileExtension = fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf("."));
string ecnFolderPath = _AppSettings.AttachmentFolder + "LotTraveler\\" + swrNumber.ToString();
var sDocument = System.IO.Path.Combine(ecnFolderPath, fileGuid + fileExtension);
var FDir_AppData = _AppSettings.AttachmentFolder;
if (!sDocument.StartsWith(FDir_AppData)) {
// Ensure that we are serving file only inside the Fab2ApprovalAttachments folder
// and block requests outside like "../web.config"
throw new HttpException(403, "Forbidden");
}
if (!System.IO.File.Exists(sDocument)) {
return null;
}
return File(sDocument, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}
[HttpPost]
public void ReAssignOriginatorByAdmin(int workRequestID, string comments, int newOriginatorId) {
if (GlobalVars.IsAdminValueNull(GetSession()))
throw new Exception("Permission denied");
try {
LotTravDMO.ReassignOriginator(workRequestID, newOriginatorId, comments, GlobalVars.GetUserId(GetSession()));
} catch (Exception e) {
string detailedException = "";
try {
detailedException = e.InnerException.ToString();
} catch {
detailedException = e.Message;
}
string exceptionString = e.Message.ToString().Trim();
if (exceptionString.Length > 450)
exceptionString = exceptionString.Substring(0, 450);
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n ReAssignOriginatorByAdmin\r\n" + workRequestID.ToString() + "\r\n" + detailedException, EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = workRequestID, UserID = GetUserIdentityName(), DocumentType = "Lot Traveler", OperationType = "Error", Comments = "ReAssignOriginatorByAdmin - " + exceptionString });
throw new Exception(e.Message);
}
}
#if !NET8
private System.Web.HttpSessionStateBase GetSession() =>
Session;
private JsonResult GetJsonResult(object? data) =>
Json(data, JsonRequestBehavior.AllowGet);
private bool IsAjaxRequest() =>
Request.IsAjaxRequest();
#endif
#if NET8
private Microsoft.AspNetCore.Http.ISession GetSession() =>
HttpContext.Session;
private JsonResult GetJsonResult(object? data) =>
Json(data);
private bool IsAjaxRequest() =>
Request.Headers.TryGetValue("X-Requested-With", out Microsoft.Extensions.Primitives.StringValues strings) && strings[0] == "XMLHttpRequest";
#endif
private string GetUserIdentityName() =>
@User.Identity.Name;
}