HelpPageService.GetFileStreamAsync удалил ArgumentInvalidException. Заменил возвращаемый тип на Nullable.

This commit is contained in:
ngfrolov 2023-07-26 17:53:25 +05:00
parent 963da559e2
commit 84d84fb504
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
3 changed files with 14 additions and 15 deletions

View File

@ -27,11 +27,11 @@ public interface IHelpPageService
/// <summary>
/// Метод получения файла справки
/// </summary>
/// <param name="urlPage"></param>
/// <param name="pageKey"></param>
/// <param name="idCategory"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage,
Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey,
int idCategory,
CancellationToken cancellationToken);
}

View File

@ -78,20 +78,23 @@ public class HelpPageService : IHelpPageService
/// <summary>
/// Метод получения файла справки
/// </summary>
/// <param name="urlPage"></param>
/// <param name="pageKey"></param>
/// <param name="idCategory"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="ArgumentInvalidException"></exception>
public async Task<(Stream stream, string fileName)> GetFileStreamAsync(string urlPage,
/// <exception cref="NotFoundException"></exception>
public async Task<(Stream stream, string fileName)?> GetFileStreamAsync(string pageKey,
int idCategory,
CancellationToken cancellationToken)
{
urlPage = WebUtility.UrlDecode(urlPage);
pageKey = WebUtility.UrlDecode(pageKey);
var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(urlPage,
var helpPage = await helpPageRepository.GetOrDefaultByUrlPageAndIdCategoryAsync(pageKey,
idCategory,
cancellationToken) ?? throw new ArgumentInvalidException("Справки не существует", nameof(idCategory));
cancellationToken);
if(helpPage is null)
return null;
string filePath = fileStorageRepository.GetFilePath(directoryNameHelpPageFiles,
helpPage.IdCategory.ToString(),

View File

@ -89,14 +89,10 @@ public class HelpPageController : ControllerBase
idCategory,
cancellationToken);
using var fileStream = file.stream;
if (!file.HasValue)
return NotFound();
var memoryStream = new MemoryStream();
await fileStream.CopyToAsync(memoryStream,
cancellationToken);
memoryStream.Position = 0;
return File(memoryStream, "application/pdf", file.fileName);
return File(file.Value.stream, "application/pdf", file.Value.fileName);
}
/// <summary>