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

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Transactions;
@ -16,17 +15,12 @@ namespace Fab2ApprovalSystem.DMO;
public class CorrectiveActionDMO {
private readonly AppSettings _AppSettings;
private readonly WorkflowDMO wfDMO = new();
private readonly IDbConnection db = new SqlConnection(GlobalVars.DB_CONNECTION_STRING);
public CorrectiveActionDMO(AppSettings appSettings) =>
_AppSettings = appSettings;
public CorrectiveAction InsertCA(CorrectiveAction ca) {
DynamicParameters parameters = new();
parameters = new DynamicParameters();
parameters.Add("@CANo", value: ca.CANo, dbType: DbType.Int32, direction: ParameterDirection.InputOutput);
parameters.Add("@RequestorID", ca.RequestorID);
@ -151,8 +145,6 @@ public class CorrectiveActionDMO {
public CorrectiveAction GetCAItem(int caNo, int userID) {
CorrectiveAction ca = new();
//isITAR = 2;
DynamicParameters parameters = new();
parameters.Add("@CANo", value: caNo);
parameters.Add("@UserID", userID);
@ -185,8 +177,6 @@ public class CorrectiveActionDMO {
public CorrectiveAction GetCAItemReadOnly(int caNo, int userID) {
CorrectiveAction ca = new();
//isITAR = 2;
DynamicParameters parameters = new();
parameters.Add("@CANo", value: caNo);
parameters.Add("@UserID", userID);
@ -512,8 +502,6 @@ public class CorrectiveActionDMO {
}
public void StartSectionApproval(int issueID, int userID, string DSection) {
//string subRoles = wfDMO.GetSubRoleItems(issueID, (int)GlobalVars.DocumentType.CorrectiveActionSection);
// bubble the error
DynamicParameters parameters = new();
parameters.Add("@CANo", issueID);
@ -524,8 +512,6 @@ public class CorrectiveActionDMO {
}
public void ApproveSection(int issueID, int userID, string DSection) {
//string subRoles = wfDMO.GetSubRoleItems(issueID, (int)GlobalVars.DocumentType.CorrectiveActionSection);
// bubble the error
DynamicParameters parameters = new();
parameters.Add("@UserID", userID);
@ -550,8 +536,6 @@ public class CorrectiveActionDMO {
}
public void RejectSection(int issueID, int userID, string DSection, string comments) {
//string subRoles = wfDMO.GetSubRoleItems(issueID, (int)GlobalVars.DocumentType.CorrectiveActionSection);
// bubble the error
DynamicParameters parameters = new();
parameters.Add("@UserID", userID);
@ -643,131 +627,4 @@ public class CorrectiveActionDMO {
return ecnList;
}
public void AttachSave(int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
//var physicalPath = Path.Combine(Server.MapPath("~/UserUploads"), fileName);
DirectoryInfo di;
var ccPhysicalPath = _AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(_AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.Main)
};
// InsertCCAttachment(attach);
InsertCAAttachment(attach);
}
public void D4FilesAttachSave(int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
//var physicalPath = Path.Combine(Server.MapPath("~/UserUploads"), fileName);
DirectoryInfo di;
var ccPhysicalPath = _AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(_AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.D4)
};
//InsertCCAttachment(attach);
InsertCAAttachment(attach);
}
public void SaveD7PA_Attachemnt(int d7PAID, int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
//var physicalPath = Path.Combine(Server.MapPath("~/UserUploads"), fileName);
DirectoryInfo di;
var ccPhysicalPath = _AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(_AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
D7PAID = d7PAID,
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.D7)
};
InsertCAAttachment(attach);
}
public void SaveD5D6CA_Attachemnt(int d5d6CAID, int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
//var physicalPath = Path.Combine(Server.MapPath("~/UserUploads"), fileName);
DirectoryInfo di;
var ccPhysicalPath = _AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(_AppSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
D5D6CAID = d5d6CAID,
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.D5)
};
InsertCAAttachment(attach);
}
}