87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
|
|
namespace PostFundManagement.Domain.Entities;
|
|
|
|
[EntityTypeConfiguration<AwardConfiguration, Award>]
|
|
public class Award : Models.Award, ITenantEntity
|
|
{
|
|
public virtual User? Creator { get; set; }
|
|
|
|
public virtual User? Updator { get; set; }
|
|
|
|
public virtual User? Approver { get; set; }
|
|
|
|
public virtual Tenant? Tenant { get; set; }
|
|
|
|
public virtual Organisation? Organisation { get; set; }
|
|
|
|
public virtual Programme? Programme { get; set; }
|
|
|
|
public virtual Project? Project { get; set; }
|
|
|
|
public virtual Contract? Contract { get; set; }
|
|
}
|
|
|
|
public sealed class AwardConfiguration : IEntityTypeConfiguration<Award>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Award> builder)
|
|
{
|
|
builder.ToTable(nameof(Award).Pluralize());
|
|
|
|
builder.HasKey(pk => pk.Id);
|
|
builder.Property(f => f.OrganisationId).IsRequired();
|
|
builder.Property(f => f.ProgrammeId).IsRequired();
|
|
builder.Property(f => f.TenantId).IsRequired();
|
|
builder.Property(f => f.ProjectId).IsRequired(false);
|
|
builder.Property(f => f.CreatedBy).IsRequired();
|
|
builder.Property(f => f.UpdatedBy).IsRequired(false);
|
|
builder.Property(f => f.ApprovedBy).IsRequired(false);
|
|
builder.Property(f => f.CreatedAt).IsRequired().HasDefaultValueSql("now()");
|
|
builder.Property(f => f.UpdatedAt).IsRequired(false);
|
|
builder.Property(f => f.Status).IsRequired().HasConversion<int>().HasDefaultValueSql("1")
|
|
.HasSentinel(ApprovalStatus.Pending);
|
|
builder.Property(f => f.Amount).IsRequired().HasPrecision(18, 2);
|
|
|
|
builder.HasOne(f => f.Tenant)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.TenantId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Organisation)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.OrganisationId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Programme)
|
|
.WithMany(f => f.Awards)
|
|
.HasForeignKey(fk => fk.ProgrammeId)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.Project)
|
|
.WithMany(f => f.Awards)
|
|
.HasForeignKey(fk => fk.ProjectId)
|
|
.IsRequired(false)
|
|
.OnDelete(DeleteBehavior.SetNull);
|
|
|
|
builder.HasOne(f => f.Creator)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.CreatedBy)
|
|
.IsRequired()
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Updator)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.UpdatedBy)
|
|
.IsRequired(false)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Approver)
|
|
.WithMany()
|
|
.HasForeignKey(fk => fk.ApprovedBy)
|
|
.IsRequired(false)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
} |