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:
167
Fab2ApprovalSystem/Misc/LotDispositionHelper.cs
Normal file
167
Fab2ApprovalSystem/Misc/LotDispositionHelper.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using Fab2ApprovalSystem.DMO;
|
||||
using Fab2ApprovalSystem.Models;
|
||||
|
||||
namespace Fab2ApprovalSystem.Misc;
|
||||
|
||||
public class LotDispositionHelper {
|
||||
|
||||
public static string NotifyRejectionToOrginator(AppSettings appSettings, int issueID, string username, List<string> emailIst) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "LotDisposition";
|
||||
string subject = "Lot Disposition Rejection";
|
||||
string emailTemplate = "LotDispositionReject.txt";
|
||||
|
||||
foreach (string email in emailIst) {
|
||||
subject = "Lot Disposition Rejection";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[4];
|
||||
emailparams[0] = issueID.ToString();
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
emailparams[3] = username;
|
||||
userEmail = email;
|
||||
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
return userEmail;
|
||||
}
|
||||
|
||||
public static string NotifyApprovers(AppSettings appSettings, int issueID, List<string> emailIst) {
|
||||
string emailSentList = "";
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "LotDisposition";
|
||||
string subject = "Lot Disposition Assignment";
|
||||
string emailTemplate = "LotDispositionAssigned.txt";
|
||||
|
||||
foreach (string email in emailIst) {
|
||||
subject = "Lot Disposition Assignment";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = issueID.ToString();
|
||||
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 AddAdditionalApproval(AppSettings appSettings, int issueID, string emailSentList, string emailArray) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "LotDisposition";
|
||||
string subject = "Lot Disposition Assignment";
|
||||
string emailTemplate = "LotDispositionAssigned.txt";
|
||||
|
||||
string[] emailIst = emailArray.Split(new char[] { '~' });
|
||||
foreach (string email in emailIst) {
|
||||
if (email.Length > 0) {
|
||||
subject = "Lot Disposition Assignment";
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = issueID.ToString();
|
||||
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 ReAssignApproverByAdmin(AppSettings appSettings, int issueID, string email) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "LotDisposition";
|
||||
string subject = "Lot Disposition Re-Assignment";
|
||||
string emailTemplate = "LotDispositionReAssigned.txt";
|
||||
|
||||
subject = "Lot Disposition Re-Assignment" + " - Email would be sent to " + email;
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = issueID.ToString();
|
||||
emailparams[1] = issueID.ToString();
|
||||
emailparams[2] = GlobalVars.hostURL;
|
||||
userEmail = email;
|
||||
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
|
||||
}
|
||||
|
||||
public static void ReAssignApproval(AppSettings appSettings, int issueID, string email) {
|
||||
string userEmail = string.Empty;
|
||||
string senderName = "LotDisposition";
|
||||
string subject = "Lot Disposition Re-Assignment";
|
||||
string emailTemplate = "LotDispositionReAssigned.txt";
|
||||
|
||||
subject = "Lot Disposition Re-Assignment" + " - Email would be sent to " + email;
|
||||
EmailNotification en = new(appSettings, subject);
|
||||
string[] emailparams = new string[3];
|
||||
emailparams[0] = issueID.ToString();
|
||||
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, LotDispositionDMO lotDispositionDMO, int issueID, 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 physicalPath = Path.Combine(appSettings.AttachmentFolder + "LotDisposition", fileName);
|
||||
|
||||
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
Attachment attach = new() {
|
||||
IssueID = issueID,
|
||||
FileName = fileName,
|
||||
UserID = userId,
|
||||
};
|
||||
lotDispositionDMO.InsertLotDispositionAttachment(attach);
|
||||
}
|
||||
|
||||
public static string ExcelLotOpen(LotDispositionDMO lotDispositionDMO, int issueID, string userIdentityName, string lotTempPipeLine, string fullFileName, Stream stream) {
|
||||
string physicalPath;
|
||||
|
||||
var fileExtension = Path.GetExtension(fullFileName);
|
||||
string fName = userIdentityName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
|
||||
|
||||
physicalPath = Path.Combine(lotTempPipeLine, fName + "." + fileExtension);
|
||||
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
|
||||
stream.CopyTo(fileStream);
|
||||
}
|
||||
|
||||
#if !NET8
|
||||
ExcelData x = new ExcelData(physicalPath);
|
||||
var lotNumbers = x.ReadData();
|
||||
|
||||
foreach (var lotInfo in lotNumbers) {
|
||||
Lot l = new Lot();
|
||||
l.LotNumber = lotInfo.LotNo;
|
||||
l.IssueID = issueID;
|
||||
if (l.LotStatusOptionID == 0)
|
||||
l.LotStatusOption.LotStatusOptionID = (int)GlobalVars.LotStatusOption.Release;
|
||||
|
||||
lotDispositionDMO.InsertLot(l, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
FileInfo f = new(physicalPath);
|
||||
if (f.Exists)
|
||||
f.Delete();
|
||||
|
||||
return physicalPath;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user