OnProfNext/OnProfNext.Server/Configurations/BookingConfiguration.cs
2025-10-17 10:41:53 +02:00

46 lines
1.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OnProfNext.Shared.Models;
namespace OnProfNext.Server.Data.Configurations
{
public class BookingConfiguration : IEntityTypeConfiguration<Booking>
{
public void Configure(EntityTypeBuilder<Booking> builder)
{
builder.ToTable("Bookings");
builder.HasKey(b => b.Id);
builder.Property(b => b.Hours)
.HasColumnType("decimal(5,2)")
.IsRequired();
builder.Property(b => b.Date)
.IsRequired();
builder.Property(b => b.Description)
.HasMaxLength(500);
builder.Property(b => b.MandantId)
.IsRequired();
builder.HasOne(b => b.Order)
.WithMany()
.HasForeignKey(b => b.OrderId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne(b => b.User)
.WithMany()
.HasForeignKey(b => b.UserId)
.OnDelete(DeleteBehavior.Restrict);
builder.Property(b => b.CreatedAt)
.HasDefaultValueSql("GETUTCDATE()");
builder.Property(b => b.UpdatedAt)
.HasDefaultValueSql("GETUTCDATE()");
}
}
}