Add project files.

This commit is contained in:
OlgunR
2026-05-21 14:35:02 +02:00
parent b315aead20
commit dc551c2313
106 changed files with 303666 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
@page
@model DXApp.TemplateKitProject.Pages.Invoices.UploadModel
@{
ViewData["Title"] = "PDF/A Upload";
}
<h2>PDF/A Rechnung hochladen</h2>
<form method="post" enctype="multipart/form-data">
<div class="mb-3">
<label asp-for="PdfFile" class="form-label">PDF/A-Datei auswählen</label>
<input asp-for="PdfFile" type="file" class="form-control" accept=".pdf" />
<span asp-validation-for="PdfFile" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Hochladen &amp; Analysieren</button>
</form>
@if (Model.ExtractionDone)
{
<hr />
<h4>Ergebnis</h4>
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div class="alert alert-danger">@Model.ErrorMessage</div>
}
else if (Model.Result == null || !Model.Result.HasAttachments)
{
<div class="alert alert-warning">Keine Anhänge in der PDF gefunden.</div>
}
else
{
<div class="alert @(Model.Result.HasZugferdXml ? "alert-success" : "alert-warning")">
@if (Model.Result.HasZugferdXml)
{
<strong>✔ ZUGFeRD/Factur-X XML gefunden:</strong>
<span>@Model.Result.ZugferdXmlAttachment!.OriginalFileName</span>
}
else
{
<strong>⚠ Kein ZUGFeRD-XML gefunden.</strong>
}
</div>
<table class="table table-sm table-bordered">
<thead class="table-light">
<tr>
<th>Dateiname</th>
<th>Größe</th>
<th>ZUGFeRD?</th>
<th>Gespeichert unter</th>
</tr>
</thead>
<tbody>
@foreach (var a in Model.Result.Attachments)
{
<tr class="@(a.IsZugferdXml ? "table-success" : "")">
<td>@a.OriginalFileName</td>
<td>@($"{a.FileSizeBytes:N0}") Bytes</td>
<td>@(a.IsZugferdXml ? "✔ Ja" : "Nein")</td>
<td><small class="text-muted">@a.SavedFilePath</small></td>
</tr>
}
</tbody>
</table>
}
}

View File

@@ -0,0 +1,51 @@
using DXApp.TemplateKitProject.Models;
using DXApp.TemplateKitProject.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace DXApp.TemplateKitProject.Pages.Invoices;
public class UploadModel(
PdfAttachmentExtractorService extractor,
ILogger<UploadModel> logger) : PageModel
{
[BindProperty]
public IFormFile? PdfFile { get; set; }
public PdfExtractionResult? Result { get; private set; }
public bool ExtractionDone { get; private set; }
public string? ErrorMessage { get; private set; }
public void OnGet()
{ }
public async Task<IActionResult> OnPostAsync()
{
if (PdfFile is null || PdfFile.Length == 0)
{
ModelState.AddModelError(nameof(PdfFile), "Bitte eine PDF-Datei auswählen.");
return Page();
}
if (!PdfFile.FileName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
{
ModelState.AddModelError(nameof(PdfFile), "Nur PDF-Dateien sind erlaubt.");
return Page();
}
ExtractionDone = true;
try
{
await using var stream = PdfFile.OpenReadStream();
Result = extractor.ExtractAttachments(stream, PdfFile.FileName);
}
catch (Exception ex)
{
logger.LogError(ex, "Fehler beim Verarbeiten der Datei '{FileName}'.", PdfFile.FileName);
ErrorMessage = $"Fehler beim Verarbeiten der Datei: {ex.Message}";
}
return Page();
}
}