Use client name and creation date for PDF downloads
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user