OnProfNext/OnProfNext.Server/Configurations/UserConfiguration.cs
Marc Wieland 6bcf3e881b Init
2025-10-13 13:21:53 +02:00

59 lines
1.7 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OnProfNext.Shared.Models;
//Konfiguriert die User-Entität für Entity Framework Core
namespace OnProfNext.Server.Configurations
{
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> entity)
{
entity.ToTable("Users");
// Primary Key
entity.HasKey(u => u.Id);
// Username
entity.Property(u => u.Username)
.IsRequired()
.HasMaxLength(50);
// Email
entity.Property(u => u.Email)
.IsRequired()
.HasMaxLength(100);
// Password Hash (wird nicht angezeigt, aber wichtig)
entity.Property(u => u.PasswordHash)
.IsRequired()
.HasMaxLength(512);
// First / Last Name
entity.Property(u => u.FirstName)
.HasMaxLength(100);
entity.Property(u => u.LastName)
.HasMaxLength(100);
// Mandant
entity.Property(u => u.MandantId)
.HasDefaultValue(1);
// Aktivitätsstatus
entity.Property(u => u.IsActive)
.HasDefaultValue(true);
// Timestamps
entity.Property(u => u.CreatedAt)
.HasDefaultValueSql("SYSDATETIME()")
.ValueGeneratedOnAdd();
entity.Property(u => u.UpdatedAt)
.HasDefaultValueSql("SYSDATETIME()")
.ValueGeneratedOnAddOrUpdate();
}
}
}