53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
|
|
namespace PostFundManagement.Domain.Entities;
|
|
|
|
[EntityTypeConfiguration<ContractConfiguration, Contract>]
|
|
public class Contract : Models.Contract, ITenantEntity
|
|
{
|
|
public virtual Tenant? Tenant { get; set; }
|
|
|
|
public virtual Award? Award { get; set; }
|
|
|
|
public virtual User? Creator { get; set; }
|
|
}
|
|
|
|
public sealed class ContractConfiguration : IEntityTypeConfiguration<Contract>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Contract> builder)
|
|
{
|
|
builder.ToTable(nameof(Contract).Pluralize());
|
|
|
|
builder.HasKey(pk => pk.Id);
|
|
builder.Property(f => f.TenantId).IsRequired();
|
|
builder.HasIndex(f => f.AwardId).IsUnique();
|
|
builder.Property(f => f.AwardId).IsRequired();
|
|
builder.Property(f => f.CreatedBy).IsRequired();
|
|
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
|
builder.Property(f => f.ExternalSignatureId).IsRequired(false);
|
|
builder.Property(f => f.SignedDocumentUrl).IsRequired(false);
|
|
builder.Property(f => f.EffectiveAt).IsRequired(false);
|
|
builder.Property(f => f.ExpiresAt).IsRequired(false);
|
|
builder.Property(f => f.TotalValue).IsRequired().HasPrecision(18, 2);
|
|
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
|
.HasSentinel(ContractStatus.Draft);
|
|
|
|
builder.HasOne(f => f.Tenant)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.TenantId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Award)
|
|
.WithOne(f => f.Contract)
|
|
.HasForeignKey<Domain.Entities.Contract>(fk => fk.AwardId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Creator)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.CreatedBy)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
} |