Files
DXApp/DXApp.TemplateKitProject/Pages/Invoices/ViewPdf.cshtml.cs
2026-06-09 11:48:49 +02:00

24 lines
762 B
C#

using DXApp.TemplateKitProject.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace DXApp.TemplateKitProject.Pages.Invoices;
public class ViewPdfModel(AppDbContext db) : PageModel
{
public async Task<IActionResult> OnGetAsync(int id)
{
var invoice = await db.ZugferdInvoices
.FirstOrDefaultAsync(i => i.Id == id);
if (invoice is null || string.IsNullOrEmpty(invoice.ResultFilePath))
return NotFound();
if (!System.IO.File.Exists(invoice.ResultFilePath))
return NotFound();
var bytes = await System.IO.File.ReadAllBytesAsync(invoice.ResultFilePath);
return File(bytes, "application/pdf");
}
}