- Replaced button in `Details.cshtml` with a link to a new document viewer page. - Created `DocumentViewer.cshtml` to display PDFs using an iframe, with a back button and a link to an experimental DevExpress viewer. - Introduced `DocumentViewerModel` in `DocumentViewer.cshtml.cs` for handling invoice ID and PDF URL. - Updated `OnGetAsync` in `ViewPdf.cshtml.cs` to set `Content-Disposition` to inline for better PDF rendering in the browser.
43 lines
1.4 KiB
C#
43 lines
1.4 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)
|
|
{
|
|
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);
|
|
|
|
// Wichtig: keine "attachment" Content-Disposition setzen
|
|
// wir setzen inline (oder lassen es weg) damit Browser im Viewer darstellt
|
|
Response.Headers["Content-Disposition"] = $"inline; filename=\"{Path.GetFileName(invoice.ResultFilePath)}\"";
|
|
|
|
return File(bytes, "application/pdf");
|
|
}
|
|
} |