Use client name and creation date for PDF downloads

This commit is contained in:
DmitriyFadin
2026-09-30 17:08:53 +03:00
parent ca18fc196d
commit acdfc2f46d
2 changed files with 10 additions and 1 deletions
@@ -1,4 +1,5 @@
using System.Security.Claims;
using System.Globalization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
@@ -18,6 +19,9 @@ public class ExportModel(IPlanReader reader, IPlanPdfExporter exporter) : PageMo
var client = await reader.GetClientAsync(plan.ClientId, trainerId);
if (client == null) return NotFound();
Response.Headers.CacheControl = "no-store";
return File(exporter.Export(plan, client), "application/pdf", $"training-program-{id}.pdf");
var clientName = string.Concat(client.Name.Select(character =>
char.IsControl(character) || "<>:\"/\\|?*".Contains(character) ? '_' : character)).Trim();
var createdDate = plan.CreatedAtUtc.ToLocalTime().ToString("dd.MM.yyyy", CultureInfo.InvariantCulture);
return File(exporter.Export(plan, client), "application/pdf", $"{clientName} — {createdDate}.pdf");
}
}