Files
DXApp/DXApp.TemplateKitProject/Data/AppDbContext.cs
OlgunR 920dce13d5 Add support for invoice attachments
Introduced the `InvoiceAttachment` entity and its relationship with `ZugferdInvoice` to manage extracted invoice attachments. Updated `AppDbContext` and added a migration to create the `InvoiceAttachments` table with cascading delete behavior and an index for optimized queries.

Enhanced the UI to display attachments in `Details.cshtml`, including file type icons, file size, and extraction date. Added a new `ViewAttachment` page to render or download attachments based on their type, with support for XML, plain text, images, and downloads.

Implemented `AttachmentViewerService` to determine viewer types and MIME types for attachments. Registered the service in the DI container. Updated `Upload.cshtml.cs` to save extracted attachments to the database.

Improved user experience with syntax highlighting for XML files and appropriate messages for unsupported file types.
2026-06-02 15:03:37 +02:00

46 lines
1.7 KiB
C#

using DXApp.TemplateKitProject.Models;
using Microsoft.EntityFrameworkCore;
namespace DXApp.TemplateKitProject.Data;
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<ZugferdInvoice> ZugferdInvoices { get; set; }
public DbSet<InvoiceAttachment> InvoiceAttachments { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ZugferdInvoice>(entity =>
{
// Index für Performance-Optimierung der Rechnungsliste
entity.HasIndex(e => e.ImportedAt)
.HasDatabaseName("IX_ZugferdInvoices_ImportedAt");
// Index für Duplikatprüfung
entity.HasIndex(e => new { e.InvoiceNumber, e.SellerTaxId })
.HasDatabaseName("IX_ZugferdInvoices_InvoiceNumber_SellerTaxId");
// Decimal-Präzision explizit festlegen (behebt EF Core Warnung)
entity.Property(e => e.TotalAmount)
.HasColumnType("decimal(18,2)");
entity.Property(e => e.TaxAmount)
.HasColumnType("decimal(18,2)");
// Relationship: One-to-Many mit InvoiceAttachments
entity.HasMany(e => e.Attachments)
.WithOne(a => a.ZugferdInvoice)
.HasForeignKey(a => a.ZugferdInvoiceId)
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<InvoiceAttachment>(entity =>
{
// Index für schnelleres Laden der Attachments einer Rechnung
entity.HasIndex(e => e.ZugferdInvoiceId)
.HasDatabaseName("IX_InvoiceAttachments_ZugferdInvoiceId");
});
}
}