diff --git a/Distribution/Data/AppDBContext.cs b/Distribution/Data/AppDBContext.cs index 94dd9de..79a4e39 100644 --- a/Distribution/Data/AppDBContext.cs +++ b/Distribution/Data/AppDBContext.cs @@ -56,6 +56,10 @@ public class AppDBContext(DbContextOptions options) : DbContext(op public DbSet Claims { get; set; } public DbSet SupplierClaims { get; set; } public DbSet SupplierClaimItems { get; set; } + public DbSet RegionalTargets { get; set; } + public DbSet RegionalBudgets { get; set; } + public DbSet RegionAgencyMaps { get; set; } + public DbSet RegionalTaxRules { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -373,6 +377,28 @@ public class AppDBContext(DbContextOptions options) : DbContext(op .HasForeignKey(t => t.FK_OrderId) .OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity() + .HasIndex(t => new { t.FK_RegionId, t.Period }) + .IsUnique(); + + modelBuilder.Entity() + .HasIndex(b => new { b.FK_RegionId, b.Period }) + .IsUnique(); + + modelBuilder.Entity() + .HasIndex(m => new { m.FK_RegionId, m.FK_AgencyUserId }) + .IsUnique(); + + modelBuilder.Entity() + .HasOne(m => m.AgencyUser) + .WithMany() + .HasForeignKey(m => m.FK_AgencyUserId) + .OnDelete(DeleteBehavior.Restrict); + + modelBuilder.Entity() + .HasIndex(r => r.FK_RegionId) + .IsUnique(); + Seed.RoleAndPermissionSeed.Apply(modelBuilder); } } diff --git a/Distribution/Models/RegionAgencyMap.cs b/Distribution/Models/RegionAgencyMap.cs new file mode 100644 index 0000000..a91df42 --- /dev/null +++ b/Distribution/Models/RegionAgencyMap.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Distribution.Models +{ + public class RegionAgencyMap : Template + { + public Guid FK_RegionId { get; set; } + [ForeignKey("FK_RegionId")] + public Region Region { get; set; } + + /// User holding the RegionalAgency role that is mapped to this region. + public Guid FK_AgencyUserId { get; set; } + [ForeignKey("FK_AgencyUserId")] + public User AgencyUser { get; set; } + } +} diff --git a/Distribution/Models/RegionalBudget.cs b/Distribution/Models/RegionalBudget.cs new file mode 100644 index 0000000..3922b20 --- /dev/null +++ b/Distribution/Models/RegionalBudget.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Distribution.Models +{ + public class RegionalBudget : Template + { + public Guid FK_RegionId { get; set; } + [ForeignKey("FK_RegionId")] + public Region Region { get; set; } + + public string Period { get; set; } + public decimal BudgetAmount { get; set; } + } +} diff --git a/Distribution/Models/RegionalTarget.cs b/Distribution/Models/RegionalTarget.cs new file mode 100644 index 0000000..e5e6f82 --- /dev/null +++ b/Distribution/Models/RegionalTarget.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Distribution.Models +{ + public class RegionalTarget : Template + { + public Guid FK_RegionId { get; set; } + [ForeignKey("FK_RegionId")] + public Region Region { get; set; } + + public string Period { get; set; } + public decimal TargetValue { get; set; } + } +} diff --git a/Distribution/Models/RegionalTaxRule.cs b/Distribution/Models/RegionalTaxRule.cs new file mode 100644 index 0000000..84d2ab2 --- /dev/null +++ b/Distribution/Models/RegionalTaxRule.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Distribution.Models +{ + public class RegionalTaxRule : Template + { + public Guid FK_RegionId { get; set; } + [ForeignKey("FK_RegionId")] + public Region Region { get; set; } + + public string RuleConfig { get; set; } + } +}