Viewer to Server
This commit is contained in:
@ -6,27 +6,27 @@ namespace OI.Metrology.Archive.Services;
|
||||
|
||||
using OI.Metrology.Archive.Models;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Repositories;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
public class AttachmentsService : IAttachmentsService
|
||||
{
|
||||
|
||||
private readonly IMetrologyRepo _Repo;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IMetrologyRepository _MetrologyRepository;
|
||||
|
||||
public AttachmentsService(AppSettings appSettings, IMetrologyRepo repo)
|
||||
public AttachmentsService(AppSettings appSettings, IMetrologyRepository metrologyRepository)
|
||||
{
|
||||
_Repo = repo;
|
||||
_AppSettings = appSettings;
|
||||
_MetrologyRepository = metrologyRepository;
|
||||
}
|
||||
protected Stream GetAttachmentStream(string tableName, Guid attachmentId, string filename)
|
||||
{
|
||||
if (attachmentId.Equals(Guid.Empty))
|
||||
throw new Exception("No attachments found");
|
||||
|
||||
DateTime insertDate = Convert.ToDateTime(_Repo.GetAttachmentInsertDateByGUID(tableName, attachmentId));
|
||||
DateTime insertDate = Convert.ToDateTime(_MetrologyRepository.GetAttachmentInsertDateByGUID(tableName, attachmentId));
|
||||
int year = insertDate.Year;
|
||||
DateTime d = insertDate;
|
||||
CultureInfo cul = CultureInfo.CurrentCulture;
|
||||
@ -63,7 +63,7 @@ public class AttachmentsService : IAttachmentsService
|
||||
|
||||
public Stream GetAttachmentStreamByTitle(ToolType toolType, bool header, string title, string filename)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
|
||||
string queryString = "SELECT * FROM " + toolType.DataTableName + " WHERE AttachmentId = @attachmentId";
|
||||
@ -103,19 +103,19 @@ public class AttachmentsService : IAttachmentsService
|
||||
if (header)
|
||||
{
|
||||
tableName = toolType.HeaderTableName;
|
||||
attachmentId = _Repo.GetHeaderAttachmentIDByTitle(toolType.ID, title);
|
||||
attachmentId = _MetrologyRepository.GetHeaderAttachmentIDByTitle(toolType.ID, title);
|
||||
}
|
||||
else
|
||||
{
|
||||
tableName = toolType.DataTableName;
|
||||
attachmentId = _Repo.GetDataAttachmentIDByTitle(toolType.ID, title);
|
||||
attachmentId = _MetrologyRepository.GetDataAttachmentIDByTitle(toolType.ID, title);
|
||||
}
|
||||
return GetAttachmentStream(tableName, attachmentId, filename);
|
||||
}
|
||||
|
||||
public Stream GetAttachmentStreamByAttachmentId(ToolType toolType, bool header, Guid attachmentId, string filename)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
string tableName;
|
||||
if (header)
|
||||
@ -126,7 +126,7 @@ public class AttachmentsService : IAttachmentsService
|
||||
}
|
||||
public Stream GetAttachmentStreamByAttachmentIdArchive(ToolType toolType, bool header, Guid attachmentId, string filename)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
string tableName;
|
||||
if (header)
|
||||
@ -139,21 +139,21 @@ public class AttachmentsService : IAttachmentsService
|
||||
|
||||
private void SaveAttachment(ToolType toolType, long headerId, string dataUniqueId, string filename, Microsoft.AspNetCore.Http.IFormFile uploadedFile)
|
||||
{
|
||||
if (toolType == null)
|
||||
if (toolType is null)
|
||||
throw new Exception("Invalid tool type");
|
||||
|
||||
using System.Transactions.TransactionScope trans = _Repo.StartTransaction();
|
||||
using System.Transactions.TransactionScope trans = _MetrologyRepository.StartTransaction();
|
||||
Guid attachmentId = Guid.Empty;
|
||||
string tableName = "";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dataUniqueId))
|
||||
{
|
||||
attachmentId = _Repo.GetHeaderAttachmentID(toolType.ID, headerId);
|
||||
attachmentId = _MetrologyRepository.GetHeaderAttachmentID(toolType.ID, headerId);
|
||||
tableName = toolType.HeaderTableName;
|
||||
}
|
||||
else
|
||||
{
|
||||
attachmentId = _Repo.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
|
||||
attachmentId = _MetrologyRepository.GetDataAttachmentID(toolType.ID, headerId, dataUniqueId);
|
||||
tableName = toolType.DataTableName;
|
||||
}
|
||||
if (Equals(attachmentId, Guid.Empty))
|
||||
|
Reference in New Issue
Block a user