mesa-fab-approval/Fab2ApprovalSystem/Misc/PartsRequestHelper.cs
Mike Phares b99b721458 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
2024-12-11 09:29:01 -07:00

49 lines
1.7 KiB
C#

using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class PartsRequestHelper {
public static void SendEmailNotification(AppSettings appSettings, string username, string subject, int prNumber, string toEmail, string emailTemplate) {
string senderName = "Parts Request";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = prNumber.ToString();
emailparams[1] = prNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "Parts Request";
emailparams[4] = username;
string userEmail = toEmail;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void AttachSave(AppSettings appSettings, PartsRequestDMO partsRequestDMO, int prNumber, 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);
string prFolderPath = appSettings.AttachmentFolder + "PartsRequest\\" + prNumber.ToString();
DirectoryInfo di = new(prFolderPath);
if (!di.Exists)
di.Create();
var physicalPath = Path.Combine(prFolderPath, fileName);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
PartsRequestAttachment attach = new() {
PRNumber = prNumber,
FileName = fileName,
UserID = userId,
};
partsRequestDMO.InsertAttachment(attach);
}
}