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:
464
Fab2ApprovalSystem/Misc/CorrectiveActionHelper.cs
Normal file
464
Fab2ApprovalSystem/Misc/CorrectiveActionHelper.cs
Normal file
@ -0,0 +1,464 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Fab2ApprovalSystem.DMO;
|
||||
using Fab2ApprovalSystem.Models;
|
||||
|
||||
namespace Fab2ApprovalSystem.Misc;
|
||||
|
||||
public class CorrectiveActionHelper {
|
||||
|
||||
public static void ProcessCARDueDates(AppSettings appSettings, CAD3D5D7Due dueCA, CorrectiveAction ca, LoginModel user) {
|
||||
string[] emailparams = new string[7];
|
||||
string emailTemplate = "D3D5D7Due.txt";
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action " + dueCA.ItemDue + " " + dueCA.ExpiryType + " - " + Functions.ReturnCANoStringFormat(dueCA.CANo);
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(dueCA.CANo);
|
||||
emailparams[1] = dueCA.CANo.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = dueCA.ExpiryType;
|
||||
emailparams[4] = dueCA.ItemDue;
|
||||
if (ca.D3DueDate != null) {
|
||||
emailparams[5] = ca.D3DueDate is null ? string.Empty : ca.D3DueDate.Value.ToString();
|
||||
} else {
|
||||
emailparams[5] = "N/A";
|
||||
}
|
||||
if (ca.D5D7DueDate != null) {
|
||||
emailparams[6] = ca.D5D7DueDate is null ? string.Empty : ca.D5D7DueDate.Value.ToString();
|
||||
} else {
|
||||
emailparams[6] = "N/A";
|
||||
}
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, user.Email, "jonathan.ouellette@infineon.com", subject, emailparams);
|
||||
}
|
||||
|
||||
public static void NotifyUsersDSectionApproved(AppSettings appSettings, int issueID, string dSection, string userEmail) {
|
||||
string senderName = "CorrectiveAction";
|
||||
string emailTemplate = "CorrectiveActionSectionApproved.txt";
|
||||
string subject = "Corrective Action Section Approval - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[4];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = dSection;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static void NotifyForD5D6D7Validation(AppSettings appSettings, int issueID, string dSection, string userEmail) {
|
||||
string senderName = "CorrectiveAction";
|
||||
string emailTemplate = "CorrectiveActionSectionApproved.txt";
|
||||
string subject = "Corrective Action Section Approval - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[4];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = dSection;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static void NotifySectionRejection(AppSettings appSettings, int issueID, int loggedInUserId, string section, string comment, LoginModel recipient, LoginModel loggedInUser) {
|
||||
string senderName = "CorrectiveAction";
|
||||
string recipientEmail = recipient.Email;
|
||||
string emailTemplate = "CorrectiveActionSectionRejection.txt";
|
||||
string subject = "Corrective Action Rejection - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[6];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = section;
|
||||
emailparams[4] = loggedInUser.FirstName + " " + loggedInUser.LastName;
|
||||
emailparams[5] = comment;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, recipientEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static void NotifySectionRejection(AppSettings appSettings, int issueID, string section, string comment, LoginModel recipient, LoginModel loggedInUser) {
|
||||
string senderName = "CorrectiveAction";
|
||||
string recipientEmail = recipient.Email;
|
||||
string emailTemplate = "CorrectiveActionSectionRejection.txt";
|
||||
string subject = "Corrective Action Rejection - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[6];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = section;
|
||||
emailparams[4] = loggedInUser.FirstName + " " + loggedInUser.LastName;
|
||||
emailparams[5] = comment;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, recipientEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static string NotifyCompletionOf8D(AppSettings appSettings, int issueID, DateTime? followUpDate) {
|
||||
string emailSentList = "";
|
||||
string senderName = "CorrectiveAction";
|
||||
string emailTemplate = "CorrectiveActionCompleted.txt";
|
||||
List<string> emailIst = MiscDMO.Get8DEmailListForClosureNotification(issueID);
|
||||
string subject = "Corrective Action Completion - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[4];
|
||||
foreach (string email in emailIst) {
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = GlobalVars.hostURL;
|
||||
emailparams[2] = issueID.ToString();
|
||||
emailparams[3] = followUpDate is null ? string.Empty : followUpDate.Value.ToString();
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
}
|
||||
|
||||
return emailSentList;
|
||||
}
|
||||
|
||||
public static string NotifyClosureOf8D(AppSettings appSettings, int issueID) {
|
||||
string emailSentList = "";
|
||||
string senderName = "CorrectiveAction";
|
||||
string emailTemplate = "CorrectiveActionClosed.txt";
|
||||
List<string> emailIst = MiscDMO.Get8DEmailListForClosureNotification(issueID);
|
||||
string subject = "Corrective Action Follow Up Closure - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
foreach (string email in emailIst) {
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = GlobalVars.hostURL;
|
||||
emailparams[2] = issueID.ToString();
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
}
|
||||
|
||||
return emailSentList;
|
||||
}
|
||||
|
||||
public static string NotifyActionItemCompletion(AppSettings appSettings, int issueID, DateTime? dueDate, int? recipientId, string template) {
|
||||
string emailSentList = "";
|
||||
string emailTemplate = template;
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string email = MiscDMO.GetEmail(recipientId);
|
||||
string subject = "8D Action Item Completion - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[5];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = dueDate is null ? string.Empty : dueDate.Value.ToString();
|
||||
emailparams[2] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
|
||||
emailparams[3] = GlobalVars.hostURL;
|
||||
emailparams[4] = issueID.ToString();
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
return email;
|
||||
}
|
||||
|
||||
public static string NotifyActionItemOwner(AppSettings appSettings, int issueID, DateTime? dueDate, int? responsibleOwnerID, string template) {
|
||||
string emailSentList = "";
|
||||
string emailTemplate = template;
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string email = MiscDMO.GetEmail(responsibleOwnerID);
|
||||
string subject = "Action Item in " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[5];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = dueDate is null ? string.Empty : dueDate.Value.ToString();
|
||||
emailparams[2] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
|
||||
emailparams[3] = GlobalVars.hostURL;
|
||||
emailparams[4] = issueID.ToString();
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
return email;
|
||||
}
|
||||
|
||||
public static void NotifyAssignee(AppSettings appSettings, int issueID, string template, DateTime? D3DueDate, DateTime? D5D7DueDate, string email) {
|
||||
string emailSentList = "";
|
||||
string emailTemplate = template;
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "CAR Assigned - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[6];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = issueID.ToString();
|
||||
emailparams[4] = D3DueDate is not null ? D3DueDate.Value.ToString() : "N/A";
|
||||
emailparams[5] = D5D7DueDate is not null ? D5D7DueDate.Value.ToString() : "N/A";
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
}
|
||||
|
||||
public static void NotifyRequestor(AppSettings appSettings, int issueID, DateTime? dueDate, string template, string email) {
|
||||
string emailSentList = "";
|
||||
string emailTemplate = template;
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action Assignment - " + Functions.ReturnCANoStringFormat(issueID);
|
||||
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[5];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = dueDate is null ? string.Empty : dueDate.Value.ToString();
|
||||
emailparams[2] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
|
||||
emailparams[3] = GlobalVars.hostURL;
|
||||
emailparams[4] = issueID.ToString();
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
}
|
||||
|
||||
public static string AddAdditionalApproval(AppSettings appSettings, int issueID, string emailSentList, string emailArray) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string emailTemplate = "CorrectiveActionAssigned.txt";
|
||||
string subject = "Corrective Action Assignment - Final Approval";
|
||||
|
||||
string[] emailIst = emailArray.Split(new char[] { '~' });
|
||||
foreach (string email in emailIst) {
|
||||
if (email.Length > 0) {
|
||||
subject = "Corrective Action Assignment";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
userEmail = email;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
}
|
||||
}
|
||||
|
||||
return emailSentList;
|
||||
}
|
||||
|
||||
public static string NotifyApprovers(AppSettings appSettings, int issueID, List<string> emailIst) {
|
||||
string emailSentList = "";
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action Assignment";
|
||||
string emailTemplate = "CorrectiveActionAssigned.txt";
|
||||
|
||||
foreach (string email in emailIst) {
|
||||
subject = "Corrective Action Assignment - Final Approval";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
userEmail = email;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
emailSentList += email + ",";
|
||||
}
|
||||
|
||||
return emailSentList;
|
||||
}
|
||||
|
||||
public static void NotifySectionApprover(AppSettings appSettings, int issueID, string section, string userEmail) {
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action Assignment";
|
||||
string emailTemplate = "CorrectiveActionSectionAssignee.txt";
|
||||
|
||||
subject = "Corrective Action Assignment - Section Approval";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[4];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = section;
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static string NotifyRejectionToAssignee(AppSettings appSettings, int issueID, string comments, string username, List<string> emailIst) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action Rejection";
|
||||
string emailTemplate = "CorrectiveActionReject.txt";
|
||||
|
||||
foreach (string email in emailIst) {
|
||||
subject = "Corrective Action Rejection";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[5];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = username;
|
||||
emailparams[4] = comments;
|
||||
userEmail = email;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
return userEmail;
|
||||
}
|
||||
|
||||
public static void ReAssignApproval(AppSettings appSettings, int issueID, string email) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action Re-Assignment";
|
||||
string emailTemplate = "CorrectiveActionReAssigned.txt";
|
||||
|
||||
subject = "Corrective Action Re-Assignment" + " - Email would be sent to " + email;
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
userEmail = email;
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static void ReAssignApproverByAdmin(AppSettings appSettings, int issueID, string email) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "CorrectiveAction";
|
||||
string subject = "Corrective Action Re-Assignment";
|
||||
string emailTemplate = "CorrectiveActionReAssigned.txt";
|
||||
|
||||
subject = "Corrective Action Re-Assignment" + " - Email would be sent to " + email;
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
userEmail = email;
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static void AttachSave(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, 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);
|
||||
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)
|
||||
};
|
||||
|
||||
correctiveActionDMO.InsertCAAttachment(attach);
|
||||
}
|
||||
|
||||
public static void D4FilesAttachSave(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, 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);
|
||||
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)
|
||||
|
||||
};
|
||||
|
||||
correctiveActionDMO.InsertCAAttachment(attach);
|
||||
}
|
||||
|
||||
public static void SaveD7PA_Attachemnt(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, 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);
|
||||
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)
|
||||
|
||||
};
|
||||
|
||||
correctiveActionDMO.InsertCAAttachment(attach);
|
||||
}
|
||||
|
||||
public static void SaveD5D6CA_Attachemnt(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, 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);
|
||||
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)
|
||||
|
||||
};
|
||||
|
||||
correctiveActionDMO.InsertCAAttachment(attach);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user