Moved System.IO references from DMO classes to Static Helpers

Removed nugetSource from pipeline
Removed more comments
Created Static Classes for most DMO / Controller Classes
Push ConfigurationManager.AppSettings to controller
Align Tests with other Projects
This commit is contained in:
2024-12-11 09:29:01 -07:00
parent b1c6903c1c
commit b99b721458
86 changed files with 2961 additions and 4432 deletions

View File

@ -1,4 +1,14 @@
using Fab2ApprovalSystem.DMO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Web;
using System.Web.Mvc;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Misc;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.ViewModels;
@ -6,17 +16,6 @@ using Fab2ApprovalSystem.ViewModels;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Web;
using System.Web.Mvc;
namespace Fab2ApprovalSystem.Controllers;
[Authorize]
@ -24,19 +23,12 @@ namespace Fab2ApprovalSystem.Controllers;
[SessionExpireFilter]
public class LotDispositionController : Controller {
LotDispositionDMO ldDMO;
LotDispositionDMO ldDMO = new LotDispositionDMO();
WorkflowDMO wfDMO = new WorkflowDMO();
private readonly AppSettings _AppSettings;
public LotDispositionController(AppSettings appSettings) {
_AppSettings = appSettings;
ldDMO = new LotDispositionDMO(appSettings);
}
private readonly AppSettings _AppSettings = GlobalVars.AppSettings;
// GET: /LotDisposition/Create
public ActionResult Create() {
//excel.FileName = "";
//var lot =
LotDisposition lotDispo = new LotDisposition();
try {
// insert a records to get the issueID
@ -67,14 +59,6 @@ public class LotDispositionController : Controller {
lot.LotStatusOption.LotStatusOptionID = l.LotStatusOptionID;
lot.LotStatusOption.LotStatusOption = l.LotStatusOptionName;
ldDMO.InsertLot(lot, false);
//if (!mrbDMO.DoesMRBLotExist(lot.LotNumber))
//{
//get All the MRBs associated to the Parent lot
//insert the lot into the MRBChildLotNotInMRB table and NOT in the MRB Lot table for each MRB
//ldDMO.InsertChildLot_NotInTheMRB(lot.LotNumber);
//}
} catch (Exception e) {
string detailedException = "";
try {
@ -110,23 +94,6 @@ public class LotDispositionController : Controller {
}
//foreach (string lotNumber in tempLots)
//{
//===================================================================
// ONLY DO THIS PART IF THE LOT DOES NOT EXIST IN THE
//"MRBLot" TABLE AND THE "MRBChildLotNotInMRB" TABLE
//===================================================================
//if (!mrbDMO.DoesMRBLotExist(lotNumber))
//{
// //get All the MRBs associated to the Parent lot
// //insert the lot into the MRBChildLotNotInMRB table and NOT in the MRB Lot table for each MRB
// ldDMO.InsertChildLot_NotInTheMRB(lotNumber);
//}
// }
}
} catch (Exception e) {
@ -145,7 +112,6 @@ public class LotDispositionController : Controller {
return Json(issueWEL, JsonRequestBehavior.AllowGet);
}
//
// GET: /LotDisposition/Edit/5
public ActionResult Edit(int issueID) {
int isITARCompliant = 1;
@ -162,7 +128,6 @@ public class LotDispositionController : Controller {
}
if (lotDispo.CurrentStep == 1) {
List<ApproversListViewModel> userList = MiscDMO.GetPendingApproversListByDocument(issueID, lotDispo.CurrentStep, (int)GlobalVars.DocumentType.LotDisposition);
//ApproversListViewModel approver = userList.Find(delegate(ApproversListViewModel al) { return al.UserID == GlobalVars.USER_ID; });
ApproversListViewModel approver = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == (int)Session[GlobalVars.SESSION_USERID]; });
if (approver == null)
ViewBag.IsApprover = "false";
@ -170,7 +135,6 @@ public class LotDispositionController : Controller {
ViewBag.IsApprover = "true";
if (approver == null && (!(bool)Session[GlobalVars.IS_ADMIN]) && (int)Session[GlobalVars.SESSION_USERID] != lotDispo.OriginatorID) {
//return RedirectToAction("ReadOnly", lotDispo);
return RedirectToAction("ReadOnly", new { issueID = issueID });
} else {
if ((ViewBag.IsApprover == "true" || (bool)Session[GlobalVars.IS_ADMIN])
@ -194,7 +158,7 @@ public class LotDispositionController : Controller {
}
} else if (lotDispo.CurrentStep > 1) {
List<ApproversListViewModel> userList = MiscDMO.GetPendingApproversListByDocument(issueID, lotDispo.CurrentStep, (int)GlobalVars.DocumentType.LotDisposition);
//ApproversListViewModel approver = userList.Find(delegate(ApproversListViewModel al) { return al.UserID == GlobalVars.USER_ID; });
ApproversListViewModel approver = userList.Find(delegate (ApproversListViewModel al) { return al.UserID == (int)Session[GlobalVars.SESSION_USERID]; });
if (approver == null) {
ViewBag.IsApprover = "false";
@ -208,14 +172,6 @@ public class LotDispositionController : Controller {
return RedirectToAction("ReadOnly", new { issueID = issueID });
} else {
//// Check the record Lock indicator
//if ((lotDispo.RecordLockIndicator && lotDispo.RecordLockedBy != (int)Session[GlobalVars.SESSION_USERID]) || (ViewBag.IsApprover == "false"))
//{
// return RedirectToAction("ReadOnly", new { issueID = issueID });
//}
//else
// return RedirectToAction("EditStep", new { issueID = issueID });
if ((ViewBag.IsApprover == "true" || (bool)Session[GlobalVars.IS_ADMIN])
|| (int)Session[GlobalVars.SESSION_USERID] == lotDispo.OriginatorID) {
return RedirectToAction("EditStep", new { issueID = issueID });
@ -257,7 +213,6 @@ public class LotDispositionController : Controller {
}
}
//
// POST: /LotDisposition/Edit/5
[HttpPost]
@ -320,19 +275,6 @@ public class LotDispositionController : Controller {
// Check the recordlock indicator
//if ((lotDispo.RecordLockIndicator && lotDispo.RecordLockedBy != (int)Session[GlobalVars.SESSION_USERID]))
//{
// return RedirectToAction("ReadOnly", new { issueID = issueID });
//}
//else
//{
// PopulateLotStatusOptions();
// ViewBag.OriginatorList = ldDMO.GetUserList();
// ViewBag.deps = ldDMO.GetDepartments();
// ViewBag.ResponsibilityList = ldDMO.GetResponsibilityList();
// ViewBag.ResponsibilityIssueList = ldDMO.GetResponsibilityIssueList(lotDispo.ResponsibilityID);
//}
if ((ViewBag.IsApprover == "true" || (bool)Session[GlobalVars.IS_ADMIN])) {
lotDispo = ldDMO.GetLotDispositionItem(issueID, out isITARCompliant, (int)Session[GlobalVars.SESSION_USERID]);
@ -351,7 +293,6 @@ public class LotDispositionController : Controller {
return RedirectToAction("ReadOnly", new { issueID = issueID });
}
//return View(lotDispo);
} catch (Exception e) {
string detailedException = "";
try {
@ -366,7 +307,6 @@ public class LotDispositionController : Controller {
}
}
//
// GET: /LotDisposition/Delete/5
public ActionResult Delete(int id) {
return View();
@ -387,7 +327,6 @@ public class LotDispositionController : Controller {
public void PopulateLotStatusOptions() {
var lotStatusOptions = ldDMO.GetLotStatusOptions();
ViewData["LotStatusOptions"] = lotStatusOptions;
//ViewData["DefaultLotStatusOptions"] = lotStatusOptions.First();
}
public ActionResult EditingCustom_Read([DataSourceRequest] DataSourceRequest request, int issueID) {
@ -397,7 +336,6 @@ public class LotDispositionController : Controller {
/// <summary>
/// Updates the lot tables
/// </summary>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingCustom_Update([DataSourceRequest] DataSourceRequest request, Lot lot) {
@ -442,26 +380,19 @@ public class LotDispositionController : Controller {
}
} catch (Exception e) {
//string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Delete =" + attachmentID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
//Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n AttachmentID Disposition\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error);
//EventLogDMO.Add(new WinEventLog() { UserID = @User.Identity.Name, OperationType = "Error", Comments = exceptionString });
//throw new Exception(e.Message);
}
return Json(new[] { attachment }.ToDataSourceResult(request, ModelState));
}
//[AcceptVerbs(HttpVerbs.Post)]
[HttpPost]
public void DeleteAttachment(int attachmentID, string fileName) {
try {
if (ModelState.IsValid) {
ldDMO.DeleteLotDispoAttachment(attachmentID);
//var physicalPath = Path.Combine(Server.MapPath("~/UserUploads"), fileName);
var physicalPath = Path.Combine(_AppSettings.AttachmentFolder + "LotDisposition", fileName);
var physicalPath = System.IO.Path.Combine(_AppSettings.AttachmentFolder + "LotDisposition", fileName);
FileInfo f = new FileInfo(physicalPath);
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
if (f.Exists)
f.Delete();
@ -491,20 +422,16 @@ public class LotDispositionController : Controller {
if (files != null) {
int userId = (int)Session[GlobalVars.SESSION_USERID];
foreach (var file in files) {
ldDMO.AttachSave(issueID, userId, file.FileName, file.InputStream);
LotDispositionHelper.AttachSave(_AppSettings, ldDMO, issueID, userId, file.FileName, file.InputStream);
}
}
//var model = ldDMO.GetLotDispoAttachments(issueID);
return Content("");
}
public JsonResult SearchLots(string searchText, string searchBy) {
List<String> lotlist = MiscDMO.SearchLots(searchText, searchBy).Select(x => x.LotNumber).ToList<String>();
//IEnumerable<Lot> lotlist = MiscDMO.SearchLots(searchText, searchBy);
return Json(lotlist, JsonRequestBehavior.AllowGet);
}
@ -546,7 +473,7 @@ public class LotDispositionController : Controller {
byte currentValue = (byte)pi.GetValue(sl, null);
if (currentValue == (int)GlobalVars.LotStatusOption.Release || currentValue == (int)GlobalVars.LotStatusOption.CloseToQDB) {
releaseCount++;
//required to update the lot status option
// required to update the lot status option
if (currentValue == (int)GlobalVars.LotStatusOption.CloseToQDB)
closeToQDBCount++;
} else if (currentValue == (int)GlobalVars.LotStatusOption.Scrap)
@ -586,8 +513,6 @@ public class LotDispositionController : Controller {
sl.IssueID = issueID;
foreach (PropertyInfo pi in sl.GetType().GetProperties()) {
if (pi.Name.ToLower().StartsWith("lot") && pi.Name.ToLower().EndsWith("state")) {
//byte currentValue = (byte)pi.GetValue(sl, null);
//if (currentValue != 2)
pi.SetValue(sl, (byte)1, null);
}
}
@ -616,8 +541,6 @@ public class LotDispositionController : Controller {
sl.IssueID = issueID;
foreach (PropertyInfo pi in sl.GetType().GetProperties()) {
if (pi.Name.ToLower().StartsWith("lot") && pi.Name.ToLower().EndsWith("state")) {
//byte currentValue = (byte)pi.GetValue(sl, null);
//if (currentValue != 2)
pi.SetValue(sl, (byte)2, null);
}
}
@ -727,14 +650,10 @@ public class LotDispositionController : Controller {
/// Get a list of Approvers and the status
/// </summary>
public ActionResult GetApproversList([DataSourceRequest] DataSourceRequest request, int issueID, byte step) {
//return Json(ldDMO.GetApproversList(issueID, step).ToDataSourceResult(request));
return Json(MiscDMO.GetApproversListByDocument(issueID, step, (int)GlobalVars.DocumentType.LotDisposition).ToDataSourceResult(request));
}
public JsonResult GetAllUsersList() {
//var userList = ldDMO.GetApprovedApproversList(issueID, currentStep);
//return Json(userList, JsonRequestBehavior.AllowGet);
UserAccountDMO userDMO = new UserAccountDMO();
IEnumerable<LoginModel> userlist = userDMO.GetAllUsers();
return Json(userlist, JsonRequestBehavior.AllowGet);
@ -756,24 +675,7 @@ public class LotDispositionController : Controller {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Error", Comments = "ReAssignApproval - " + exceptionString });
throw new Exception(e.Message);
}
string emailTemplate = "LotDispositionReAssigned.txt";
string userEmail = string.Empty;
string subject = "Lot Disposition Re-Assignment";
string senderName = "LotDisposition";
subject = "Lot Disposition Re-Assignment" + " - Email would be sent to " + email;
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
LotDispositionHelper.ReAssignApproval(_AppSettings, issueID, email);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Email", Comments = "ReAssign Approver: " + email });
} catch { }
@ -795,24 +697,7 @@ public class LotDispositionController : Controller {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Error", Comments = "ReAssignApproval - " + exceptionString });
throw new Exception(e.Message);
}
string emailTemplate = "LotDispositionReAssigned.txt";
string userEmail = string.Empty;
string subject = "Lot Disposition Re-Assignment";
string senderName = "LotDisposition";
subject = "Lot Disposition Re-Assignment" + " - Email would be sent to " + email;
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
LotDispositionHelper.ReAssignApproverByAdmin(_AppSettings, issueID, email);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Email", Comments = "ReAssign Approver: " + email });
} catch { }
@ -843,33 +728,7 @@ public class LotDispositionController : Controller {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Error", Comments = "AddAdditionalApproval - " + exceptionString });
throw new Exception(e.Message);
}
string emailTemplate = "LotDispositionAssigned.txt";
string userEmail = string.Empty;
string subject = "Lot Disposition Assignment";
string senderName = "LotDisposition";
string[] emailIst = emailArray.Split(new char[] { '~' });
foreach (string email in emailIst) {
if (email.Length > 0) {
//subject = "Lot Disposition Assignment" + " - Email would be sent to " + email;
subject = "Lot Disposition Assignment";
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
}
emailSentList = LotDispositionHelper.AddAdditionalApproval(_AppSettings, issueID, emailSentList, emailArray);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Email", Comments = "Additonal Approver: " + emailSentList });
} catch { }
@ -879,32 +738,8 @@ public class LotDispositionController : Controller {
public void NotifyApprovers(int issueID, byte currentStep) {
try {
string emailSentList = "";
//List<string> emailIst = ldDMO.GetApproverEmailList(@issueID, currentStep).Distinct().ToList();
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(@issueID, currentStep, (int)GlobalVars.DocumentType.LotDisposition).Distinct().ToList();
string emailTemplate = "LotDispositionAssigned.txt";
string userEmail = string.Empty;
string subject = "Lot Disposition Assignment";
string senderName = "LotDisposition";
foreach (string email in emailIst) {
subject = "Lot Disposition Assignment";
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
string emailSentList = LotDispositionHelper.NotifyApprovers(_AppSettings, issueID, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Email", Comments = "Approvers for Step " + currentStep.ToString() + ":" + emailSentList });
} catch { }
@ -924,29 +759,9 @@ public class LotDispositionController : Controller {
public void NotifyRejectionToOrginator(int issueID) {
string username = Session[GlobalVars.SESSION_USERNAME].ToString();
List<string> emailIst = ldDMO.GetRejectionOrginatorEmailList(@issueID).Distinct().ToList();
string emailTemplate = "LotDispositionReject.txt";
string userEmail = string.Empty;
string subject = "Lot Disposition Rejection";
string senderName = "LotDisposition";
foreach (string email in emailIst) {
subject = "Lot Disposition Rejection";
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[4];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = Session[GlobalVars.SESSION_USERNAME].ToString();
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
string userEmail = LotDispositionHelper.NotifyRejectionToOrginator(_AppSettings, issueID, username, emailIst);
try {
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, DocumentType = "Lot Disposition", OperationType = "Email", Comments = "Rejection: " + userEmail });
} catch { }
@ -970,7 +785,6 @@ public class LotDispositionController : Controller {
}
public ActionResult GetComments([DataSourceRequest] DataSourceRequest request, int issueID) {
//return Json(ldDMO.GetApproversList(issueID, step).ToDataSourceResult(request));
return Json(ldDMO.GetComments(issueID).ToDataSourceResult(request));
}
@ -996,14 +810,13 @@ public class LotDispositionController : Controller {
var physicalPath = "";
try {
string userIdentityName = @User.Identity.Name;
string lotTempPipeLine = ConfigurationManager.AppSettings["LotTempPipeLine"].ToString();
foreach (var file in Lotfile) {
physicalPath = ldDMO.ExcelLotOpen(issueID, userIdentityName, lotTempPipeLine, file.FileName, file.InputStream);
physicalPath = LotDispositionHelper.ExcelLotOpen(ldDMO, issueID, userIdentityName, _AppSettings.LotTempPipeLine, file.FileName, file.InputStream);
}
return Content("");
} catch {
FileInfo f = new FileInfo(physicalPath);
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
if (f.Exists)
f.Delete();
@ -1027,11 +840,10 @@ public class LotDispositionController : Controller {
}
public FileResult DownloadFile(string attachmentID) {
//fileName = "ECNForm_71132.pdf";
string fileName = ldDMO.GetFileName(attachmentID);
var sDocument = Path.Combine(_AppSettings.AttachmentFolder + "LotDisposition", fileName);
var sDocument = System.IO.Path.Combine(_AppSettings.AttachmentFolder + "LotDisposition", fileName);
var FDir_AppData = _AppSettings.AttachmentFolder;
if (!sDocument.StartsWith(FDir_AppData)) {
// Ensure that we are serving file only inside the Fab2ApprovalAttachments folder
@ -1041,7 +853,6 @@ public class LotDispositionController : Controller {
if (!System.IO.File.Exists(sDocument)) {
return null;
//throw new Exception("File not found");
}
return File(sDocument, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);