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); } }