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:
96
Fab2ApprovalSystem/Misc/ChangeControlHelper.cs
Normal file
96
Fab2ApprovalSystem/Misc/ChangeControlHelper.cs
Normal file
@ -0,0 +1,96 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user