99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
using PostFundManagement.Domain.Abstractions;
|
|
using PostFundManagement.Domain.Entities;
|
|
|
|
namespace PostFundManagement.Infrastructure.Database;
|
|
|
|
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options,
|
|
ITenantContextService tenantService) : DbContext(options)
|
|
{
|
|
private bool BypassFilter => tenantService.IsAdmin;
|
|
private long CurrentTenantId => tenantService.TenantId;
|
|
|
|
public DbSet<TenantUser> TenantUsers => Set<TenantUser>();
|
|
|
|
public DbSet<TenantOrganisation> TenantOrganisations => Set<TenantOrganisation>();
|
|
|
|
public DbSet<Tenant> Tenants => Set<Tenant>();
|
|
|
|
public DbSet<Notification> Notifications => Set<Notification>();
|
|
|
|
public DbSet<Invite> Invites => Set<Invite>();
|
|
|
|
public DbSet<Activity> Activities => Set<Activity>();
|
|
|
|
public DbSet<AuditLog> AuditLogs => Set<AuditLog>();
|
|
|
|
public DbSet<SiteVisit> SiteVisits => Set<SiteVisit>();
|
|
|
|
public DbSet<ChangeRequest> ChangeRequests => Set<ChangeRequest>();
|
|
|
|
public DbSet<ComplianceItem> ComplianceItems => Set<ComplianceItem>();
|
|
|
|
public DbSet<Issue> Issues => Set<Issue>();
|
|
|
|
public DbSet<Outcome> Outcomes => Set<Outcome>();
|
|
|
|
public DbSet<Beneficiary> Beneficiaries => Set<Beneficiary>();
|
|
|
|
public DbSet<Evidence> Evidences => Set<Evidence>();
|
|
|
|
public DbSet<Risk> Risks => Set<Risk>();
|
|
|
|
public DbSet<Indicator> Indicators => Set<Indicator>();
|
|
|
|
public DbSet<Disbursement> Disbursements => Set<Disbursement>();
|
|
|
|
public DbSet<Milestone> Milestones => Set<Milestone>();
|
|
|
|
public DbSet<Budget> Budgets => Set<Budget>();
|
|
|
|
public DbSet<Contract> Contracts => Set<Contract>();
|
|
|
|
public DbSet<Award> Awards => Set<Award>();
|
|
|
|
public DbSet<Project> Projects => Set<Project>();
|
|
|
|
public DbSet<Organisation> Organisations => Set<Organisation>();
|
|
|
|
public DbSet<Rule> Rules => Set<Rule>();
|
|
|
|
public DbSet<Programme> Programmes => Set<Programme>();
|
|
|
|
public DbSet<Portfolio> Portfolios => Set<Portfolio>();
|
|
|
|
public DbSet<Instrument> Instruments => Set<Instrument>();
|
|
|
|
public DbSet<User> Users => Set<User>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<Portfolio>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<Programme>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<Project>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<Award>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<Notification>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<TenantOrganisation>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<TenantUser>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<AuditLog>()
|
|
.HasQueryFilter(e => BypassFilter || e.TenantId == CurrentTenantId);
|
|
|
|
modelBuilder.Entity<Organisation>().HasQueryFilter(o => BypassFilter ||
|
|
Set<TenantOrganisation>().Any(to => to.TenantId == CurrentTenantId && to.OrganisationId == o.Id));
|
|
}
|
|
} |