Files
predavanja/Events-WebApi/Events.FilesAPI/Features/RegistrationsExcel/Download/RegistrationsExcelFileLocator.cs
2026-05-10 23:39:55 +02:00

28 lines
889 B
C#

using Events.FilesAPI.Infrastructure.Files;
using Events.FilesAPI.Infrastructure.Options;
using Microsoft.Extensions.Options;
namespace Events.FilesAPI.Features.RegistrationsExcel.Download;
public sealed class RegistrationsExcelFileLocator(
IHostEnvironment hostEnvironment,
IOptions<GeneratedFilesOptions> generatedFilesOptions)
{
public GeneratedFileReference? TryGet(int eventId)
{
string rootPath = Path.IsPathRooted(generatedFilesOptions.Value.OutputPath)
? generatedFilesOptions.Value.OutputPath
: Path.GetFullPath(Path.Combine(hostEnvironment.ContentRootPath, generatedFilesOptions.Value.OutputPath));
string excelPath = Path.Combine(rootPath, $"{eventId}.xlsx");
if (!File.Exists(excelPath))
return null;
return new GeneratedFileReference
{
FileName = Path.GetFileName(excelPath),
PhysicalPath = excelPath
};
}
}