This commit is contained in:
KharchenkoVV 2021-09-02 10:13:33 +05:00
commit 95733371a2
5 changed files with 10 additions and 7 deletions

View File

@ -11,7 +11,7 @@ namespace AsbCloudApp.Services
{
string RootPath { get; }
Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default);
Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default);
Task<PaginationContainer<FileInfoDto>> GetInfosAsync(int idWell,
int idCategory, string companyName = default, string fileName = default, DateTime begin = default, DateTime end = default,

View File

@ -17,7 +17,7 @@ namespace AsbCloudDb.Model
public int IdWell { get; set; }
[Column("id_author"), Comment("Id пользователя, загрузившего файл")]
public int IdAuthor { get; set; }
public int? IdAuthor { get; set; }
[Column("id_category"), Comment("id категории файла")]
public int IdCategory { get; set; }

View File

@ -39,14 +39,14 @@ namespace AsbCloudInfrastructure.Services
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
.ConfigureAwait(false);
if (matchFiles is not null) {
if (matchFiles is not null && matchFiles.Any()) {
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
var matchFilesIterator = matchFiles.GetEnumerator();
matchFilesIterator.MoveNext();
var matchFile = matchFilesIterator.Current;
while (matchFilesIterator.MoveNext())
await fileService.DeletedAsync(matchFilesIterator.Current.Id, token)
.ConfigureAwait(false);
.ConfigureAwait(false);
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
return matchFile;
@ -61,8 +61,9 @@ namespace AsbCloudInfrastructure.Services
var stream = new MemoryStream(1024 * 1024);
UniteExcelFiles(fileNames, stream);
stream.Seek(0, SeekOrigin.Begin);
return await fileService.SaveAsync(idWell, 0, idFileCategoryDrillingProgramItems, resultFileName, stream, token)
var buffer = stream.ToArray();
var fileStream = new MemoryStream(buffer);
return await fileService.SaveAsync(idWell, null, idFileCategoryDrillingProgram, resultFileName, fileStream, token)
.ConfigureAwait(false);
}

View File

@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure.Services
.ThenInclude(c => c.CompanyType);
}
public async Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
{
//save info to db
var fileInfo = new AsbCloudDb.Model.FileInfo()

View File

@ -27,6 +27,8 @@ namespace AsbCloudWebApi.Controllers
{
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
.ConfigureAwait(false);
if (fileInfo is null)
return NoContent();
var relativePath = fileService.GetFileName(fileInfo);
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
}