using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using OnProfNext.Shared.Models; namespace OnProfNext.Server.Configurations { public class OrderConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { entity.ToTable("Orders"); entity.HasKey(o => o.Id); entity.Property(o => o.Auftragsnummer) .IsRequired() .HasMaxLength(50); entity.Property(o => o.Titel) .IsRequired() .HasMaxLength(255); entity.Property(o => o.Status) .IsRequired() .HasMaxLength(50) .HasDefaultValue("Geplant"); entity.Property(o => o.Planstunden) .HasPrecision(10, 2) .HasDefaultValue(0); entity.Property(o => o.Iststunden) .HasPrecision(10, 2) .HasDefaultValue(0); entity.Property(o => o.MandantId) .IsRequired(); entity.Property(o => o.CreatedAt) .HasDefaultValueSql("GETUTCDATE()"); entity.Property(o => o.UpdatedAt) .HasDefaultValueSql("GETUTCDATE()"); entity.HasOne(o => o.Project) .WithMany(p => p.Orders) .HasForeignKey(o => o.ProjectId) .OnDelete(DeleteBehavior.Cascade); entity.HasMany(o => o.OrderUsers) .WithOne(ou => ou.Order) .HasForeignKey(ou => ou.OrderId) .OnDelete(DeleteBehavior.Cascade); } } }