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
88 lines
3.3 KiB
C#
88 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
using Fab2ApprovalSystem.DMO;
|
|
using Fab2ApprovalSystem.Models;
|
|
|
|
namespace Fab2ApprovalSystem.Misc;
|
|
|
|
public class AuditHelper {
|
|
|
|
public static List<string> GetFileNameAndDocument(AppSettings appSettings, AuditDMO auditDMO, string fileGuid, int auditNo) {
|
|
List<string> results = new();
|
|
string fileName = auditDMO.GetAuditReportAttachmentFileName(fileGuid);
|
|
string fileExtension = fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf("."));
|
|
|
|
string ecnFolderPath = appSettings.AttachmentFolder + "Audit\\" + auditNo.ToString();
|
|
string sDocument = Path.Combine(ecnFolderPath, fileGuid + fileExtension);
|
|
|
|
string FDir_AppData = appSettings.AttachmentFolder;
|
|
if (!sDocument.StartsWith(FDir_AppData)) {
|
|
sDocument = string.Empty;
|
|
}
|
|
results.Add(fileName);
|
|
results.Add(sDocument);
|
|
return results;
|
|
}
|
|
|
|
public static void AuditReportAttachSave(AppSettings appSettings, AuditDMO auditDMO, int auditNo, 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 + @"Audit\" + auditNo;
|
|
di = new DirectoryInfo(ccPhysicalPath);
|
|
if (!di.Exists)
|
|
di.Create();
|
|
|
|
var guid = Guid.NewGuid().ToString();
|
|
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"Audit\" + auditNo + @"\", guid + fileExtension);
|
|
|
|
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
|
|
stream.CopyTo(fileStream);
|
|
}
|
|
AuditReportAttachment attach = new() {
|
|
AuditNo = auditNo,
|
|
FileGUID = guid,
|
|
FileName = fileName,
|
|
UploadedByID = userId
|
|
|
|
};
|
|
|
|
auditDMO.InsertAuditReportAttachment(attach);
|
|
}
|
|
|
|
public static void SaveAndInsert(AppSettings appSettings, AuditDMO auditDMO, int caFindingsID, int auditNo, 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 + @"Audit\" + auditNo;
|
|
di = new DirectoryInfo(ccPhysicalPath);
|
|
if (!di.Exists)
|
|
di.Create();
|
|
|
|
var guid = Guid.NewGuid().ToString();
|
|
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"Audit\" + auditNo + @"\", guid + fileExtension);
|
|
|
|
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
|
|
stream.CopyTo(fileStream);
|
|
}
|
|
AuditReportAttachment attach = new() {
|
|
CAFindingsID = caFindingsID,
|
|
AuditNo = auditNo,
|
|
FileGUID = guid,
|
|
FileName = fileName,
|
|
UploadedByID = userId
|
|
|
|
};
|
|
|
|
auditDMO.InsertAuditReportAttachment(attach);
|
|
}
|
|
|
|
} |