From 717b891554b6122a6a26d87ae25ec5bd5e2aa25e Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Tue, 22 Sep 2026 07:08:57 +0200 Subject: [PATCH] Added linkage to primary tenant entities --- .../Services/Communications/CommunicationsService.cs | 8 +++++--- .../Services/Governance/GovernanceService.cs | 9 ++++++--- .../Services/Grants/GrantsService.cs | 5 +++-- .../Services/Projects/ProjectService.cs | 10 +++++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/PostFundManagement.Application/Services/Communications/CommunicationsService.cs b/PostFundManagement.Application/Services/Communications/CommunicationsService.cs index 0de5db7..a446400 100644 --- a/PostFundManagement.Application/Services/Communications/CommunicationsService.cs +++ b/PostFundManagement.Application/Services/Communications/CommunicationsService.cs @@ -1,5 +1,6 @@ using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Domain; +using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Errors; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; @@ -7,7 +8,7 @@ using PostFundManagement.Infrastructure.Database; namespace PostFundManagement.Application.Services.Communications; -public sealed class CommunicationsService(IDbContextFactory contextFactory) : ICommunicationsService +public sealed class CommunicationsService(IDbContextFactory contextFactory, ITenantContextService tenantContext) : ICommunicationsService { public async Task> SendInviteAsync(InviteRequest request, Guid userId, CancellationToken cancellationToken = default) => await Result.Try((Func>>)(async () => @@ -15,7 +16,7 @@ public sealed class CommunicationsService(IDbContextFactory contextFactory, HashService hashService) : IGovernanceService +public sealed class GovernanceService(IDbContextFactory contextFactory, HashService hashService, + ITenantContextService tenantContext) : IGovernanceService { public async Task> GetProgrammesAsync(string portfolioIdHash, CancellationToken cancellationToken = default) => await Result.Try((Func>>)(async () => @@ -144,7 +146,7 @@ public sealed class GovernanceService(IDbContextFactory co Type = request.Type, Status = ActivityStatus.Active, CreatedBy = userId, - CreatedAt = DateTime.UtcNow + CreatedAt = DateTime.UtcNow }); return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.New); @@ -189,7 +191,8 @@ public sealed class GovernanceService(IDbContextFactory co OrganisationId = request.OrganisationId, OwnedBy = request.OwnerId, Name = name, - Description = request.Description.Humanize(LetterCasing.Sentence).Trim() + Description = request.Description.Humanize(LetterCasing.Sentence).Trim(), + TenantId = tenantContext.TenantId }); return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.New); diff --git a/PostFundManagement.Application/Services/Grants/GrantsService.cs b/PostFundManagement.Application/Services/Grants/GrantsService.cs index 3784947..4e0ad2f 100644 --- a/PostFundManagement.Application/Services/Grants/GrantsService.cs +++ b/PostFundManagement.Application/Services/Grants/GrantsService.cs @@ -10,7 +10,7 @@ using PostFundManagement.Infrastructure.Database; namespace PostFundManagement.Application.Services.Grants; public sealed class GrantsService(IDbContextFactory contextFactory, HashService hashService, - [FromKeyedServices(Constants.GeneralBucketName)] IS3Service s3Service) : IGrantsService + [FromKeyedServices(Constants.GeneralBucketName)] IS3Service s3Service, ITenantContextService tenantContext) : IGrantsService { public async Task> GetContractsAsync(Pagination pagination, CancellationToken cancellationToken = default) => await Result.Try((Func>>)(async () => @@ -196,7 +196,8 @@ public sealed class GrantsService(IDbContextFactory contex Amount = request.Amount, Status = ApprovalStatus.Pending, CreatedBy = userId, - CreatedAt = DateTime.UtcNow + CreatedAt = DateTime.UtcNow, + TenantId = tenantContext.TenantId }; context.Awards.Add(award); diff --git a/PostFundManagement.Application/Services/Projects/ProjectService.cs b/PostFundManagement.Application/Services/Projects/ProjectService.cs index 60d41b3..22cc715 100644 --- a/PostFundManagement.Application/Services/Projects/ProjectService.cs +++ b/PostFundManagement.Application/Services/Projects/ProjectService.cs @@ -1,6 +1,7 @@ using PostFundManagement.Application.Abstractions.Services; using PostFundManagement.Application.Services.Shared; using PostFundManagement.Domain; +using PostFundManagement.Domain.Abstractions; using PostFundManagement.Domain.Errors; using PostFundManagement.Domain.Extensions; using PostFundManagement.Domain.Models; @@ -8,7 +9,8 @@ using PostFundManagement.Infrastructure.Database; namespace PostFundManagement.Application.Services.Projects; -public sealed class ProjectService(IDbContextFactory contextFactory, HashService hashService) : IProjectService +public sealed class ProjectService(IDbContextFactory contextFactory, HashService hashService, + ITenantContextService tenantContext) : IProjectService { public async Task UpdateProjectStatusAsync(UpdateProjectStatusRequest request, Guid userId, CancellationToken cancellationToken = default) => await Result.Try((Func>)(async () => @@ -101,7 +103,8 @@ public sealed class ProjectService(IDbContextFactory conte ProjectType = request.ProjectType, Status = ApprovalStatus.Pending, CreatedBy = userId, - CreatedAt = DateTime.UtcNow + CreatedAt = DateTime.UtcNow, + TenantId = tenantContext.TenantId }); return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, @@ -303,7 +306,8 @@ public sealed class ProjectService(IDbContextFactory conte Name = name, CreatedBy = userId, CreatedAt = DateTime.UtcNow, - Status = ApprovalStatus.Pending + Status = ApprovalStatus.Pending, + TenantId = tenantContext.TenantId }); return Result.OkIf(await context.SaveChangesAsync(cancellationToken) > 0, CreateError.New);