forked from ddrilling/AsbCloudServer
File author is optional (for drillingProgram)
This commit is contained in:
parent
a7962492af
commit
b471efc59e
@ -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,
|
||||
|
@ -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; }
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user