mesa-fab-approval/Fab2ApprovalSystem/Misc/ChangeControlHelper.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

96 lines
3.7 KiB
C#

using System;
using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class ChangeControlHelper {
public static void AttachSaveCC(AppSettings appSettings, ChangeControlDMO changeControlDMO, int planNumber, int attachID, 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 + @"ChangeControl\" + planNumber;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"ChangeControl\" + planNumber + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CCAttachment attach = new() {
ID = attachID,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
changeControlDMO.UpdateCCAttachmentDocument(attach);
}
public static void AttachSaveMeeting(AppSettings appSettings, ChangeControlDMO changeControlDMO, int planNumber, int attachID, 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 + @"ChangeControl\" + planNumber;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"ChangeControl\" + planNumber + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CCMeetingAttachment attach = new() {
ID = attachID,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
changeControlDMO.UpdateMeetingAttachmentDocument(attach);
}
public static void AttachSaveActionItem(AppSettings appSettings, ChangeControlDMO changeControlDMO, int planNumber, int attachID, 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 + @"ChangeControl\" + planNumber;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"ChangeControl\" + planNumber + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CCMeetingActionItemAll attach = new() {
ID = attachID,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
changeControlDMO.UpdateActionItemAttachment(attach);
}
}