diff --git a/PostFundManagement.Domain/Configuration/Award.cs b/PostFundManagement.Domain/Configuration/Award.cs new file mode 100644 index 0000000..de9ff68 --- /dev/null +++ b/PostFundManagement.Domain/Configuration/Award.cs @@ -0,0 +1,57 @@ +namespace PostFundManagement.Domain.Configuration; + +public class Award : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Entities.Award).Pluralize()); + + builder.HasKey(pk => pk.Id); + builder.Property(f => f.OrganisationId).IsRequired(); + builder.Property(f => f.ProgrammeId).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().HasDefaultValue(ApprovalStatus.Pending); + builder.Property(f => f.Amount).IsRequired().HasPrecision(18, 2); + + 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); + } +} \ No newline at end of file diff --git a/PostFundManagement.Domain/Entities/Award.cs b/PostFundManagement.Domain/Entities/Award.cs new file mode 100644 index 0000000..f29083e --- /dev/null +++ b/PostFundManagement.Domain/Entities/Award.cs @@ -0,0 +1,17 @@ +namespace PostFundManagement.Domain.Entities; + +[EntityTypeConfiguration] +public class Award : Models.Award +{ + public virtual User? Creator { get; set; } + + public virtual User? Updator { get; set; } + + public virtual User? Approver { get; set; } + + public virtual Organisation? Organisation { get; set; } + + public virtual Programme? Programme { get; set; } + + public virtual Project? Project { get; set; } +} \ No newline at end of file diff --git a/PostFundManagement.Domain/Entities/Programme.cs b/PostFundManagement.Domain/Entities/Programme.cs index 0f7c44b..fc76353 100644 --- a/PostFundManagement.Domain/Entities/Programme.cs +++ b/PostFundManagement.Domain/Entities/Programme.cs @@ -14,4 +14,6 @@ public class Programme : Models.Programme public virtual ICollection Rules { get; set; } = []; public virtual ICollection Projects { get; set; } = []; + + public virtual ICollection Awards { get; set; } = []; } \ No newline at end of file diff --git a/PostFundManagement.Domain/Entities/Project.cs b/PostFundManagement.Domain/Entities/Project.cs index 1440add..982fb00 100644 --- a/PostFundManagement.Domain/Entities/Project.cs +++ b/PostFundManagement.Domain/Entities/Project.cs @@ -8,4 +8,6 @@ public class Project : Models.Project public virtual User? Updator { get; set; } public virtual Programme? Programme { get; set; } + + public virtual ICollection Awards { get; set; } = []; } \ No newline at end of file diff --git a/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs b/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs index 9142b07..beaa673 100644 --- a/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs +++ b/PostFundManagement.Infrastructure/Database/ApplicationDbContext.cs @@ -4,6 +4,8 @@ namespace PostFundManagement.Infrastructure.Database; public sealed class ApplicationDbContext(DbContextOptions options) : DbContext(options) { + public DbSet Awards => Set(); + public DbSet Projects => Set(); public DbSet Organisations => Set();