Files
DXApp/DXApp.TemplateKitProject/Pages/Invoices/ViewPdf.cshtml.cs
OlgunR b515b4f523 Refactor PDF viewing and integrate DevExpress support
- Removed folder reference for "Controllers" in the project file.
- Updated `ViewPdf.cshtml` to include layout and clarify PDF output.
- Enhanced `ViewPdf.cshtml.cs` with improved logging and error handling.
- Added MVC controller services in `Program.cs` for DevExpress functionality.
- Introduced `DocumentViewerController` to manage document viewing requests.
2026-06-08 15:14:15 +02:00

40 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using DXApp.TemplateKitProject.Data;
using Microsoft.EntityFrameworkCore;
namespace DXApp.TemplateKitProject.Pages.Invoices;
public class ViewPdfModel : PageModel
{
private readonly AppDbContext _db;
private readonly ILogger<ViewPdfModel> _logger;
public ViewPdfModel(AppDbContext db, ILogger<ViewPdfModel> logger)
{
_db = db;
_logger = logger;
}
public async Task<IActionResult> OnGetAsync(int id)
{
// Sicherheit: defensive checks, gleiche Logik wie CustomReportStorageWebExtension
var invoice = await _db.ZugferdInvoices
.AsNoTracking()
.FirstOrDefaultAsync(i => i.Id == id);
if (invoice is null)
return NotFound();
if (string.IsNullOrEmpty(invoice.ResultFilePath))
return NotFound();
if (!System.IO.File.Exists(invoice.ResultFilePath))
return NotFound();
var bytes = await System.IO.File.ReadAllBytesAsync(invoice.ResultFilePath);
_logger.LogInformation("ViewPdf: Invoice {Id} ausgeliefert ({Size} Bytes).", id, bytes.Length);
return File(bytes, "application/pdf", $"{Path.GetFileName(invoice.ResultFilePath)}");
}
}