diff --git a/applications/Unity.GrantManager/src/Unity.GrantManager.Application.Contracts/GrantApplications/UpdateApplicantSummaryDto.cs b/applications/Unity.GrantManager/src/Unity.GrantManager.Application.Contracts/GrantApplications/UpdateApplicantSummaryDto.cs index cbe79cc0d..52350304e 100644 --- a/applications/Unity.GrantManager/src/Unity.GrantManager.Application.Contracts/GrantApplications/UpdateApplicantSummaryDto.cs +++ b/applications/Unity.GrantManager/src/Unity.GrantManager.Application.Contracts/GrantApplications/UpdateApplicantSummaryDto.cs @@ -16,6 +16,5 @@ public class UpdateApplicantSummaryDto public bool? IndigenousOrgInd { get; set; } public string? UnityApplicantId { get; set; } public string? FiscalDay { get; set; } - public string? FiscalMonth { get; set; } - public string? ElectoralDistrict { get; set; } + public string? FiscalMonth { get; set; } } diff --git a/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantApplications/ApplicationApplicantAppService.cs b/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantApplications/ApplicationApplicantAppService.cs index b6c9a02de..2177a6bdf 100644 --- a/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantApplications/ApplicationApplicantAppService.cs +++ b/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantApplications/ApplicationApplicantAppService.cs @@ -151,6 +151,7 @@ public async Task UpdatePartialApplicantInfoAsync(Guid appl } // Only update the fields we need to update based on the modified + // Automapper mapping ignores the ElectoralDistrict as this is different from the application level electoral district ObjectMapper.Map(input.Data, application); //-- APPLICANT INFO - SUMMARY @@ -190,6 +191,14 @@ public async Task UpdatePartialApplicantInfoAsync(Guid appl await CreateOrUpdateApplicantAddress(applicationId, application.ApplicantId, input.Data.MailingAddress); } + //-- APPLICANT ELECTORAL DISTRICT + if (input.Data.ElectoralDistrict != null + && await AuthorizationService.IsGrantedAsync(UnitySelector.Applicant.Location.Update)) + { + // Update the electoral district at the applicant level + application.Applicant.ElectoralDistrict = input.Data.ElectoralDistrict; + } + //-- APPLICANT INFO CUSTOM FIELDS if (input.Data.CustomFields?.ValueKind != JsonValueKind.Null && input.Data.WorksheetId != Guid.Empty && input.Data.CorrelationId != Guid.Empty) { diff --git a/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantManagerApplicationAutoMapperProfile.cs b/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantManagerApplicationAutoMapperProfile.cs index 77a47ff1b..1ad3ec85a 100644 --- a/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantManagerApplicationAutoMapperProfile.cs +++ b/applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantManagerApplicationAutoMapperProfile.cs @@ -106,7 +106,8 @@ public GrantManagerApplicationAutoMapperProfile() CreateMap() .IgnoreNullAndDefaultValues(); CreateMap() - .IgnoreNullAndDefaultValues(); + .IgnoreNullAndDefaultValues() + .ForMember(dest => dest.ElectoralDistrict, opt => opt.Ignore()); // Electoral district is handled separately CreateMap() .IgnoreNullAndDefaultValues(); CreateMap() diff --git a/applications/Unity.GrantManager/src/Unity.GrantManager.Application/Intakes/Handlers/DetermineElectoralDistrictHandler.cs b/applications/Unity.GrantManager/src/Unity.GrantManager.Application/Intakes/Handlers/DetermineElectoralDistrictHandler.cs index 118fa2ad3..487a6bac1 100644 --- a/applications/Unity.GrantManager/src/Unity.GrantManager.Application/Intakes/Handlers/DetermineElectoralDistrictHandler.cs +++ b/applications/Unity.GrantManager/src/Unity.GrantManager.Application/Intakes/Handlers/DetermineElectoralDistrictHandler.cs @@ -14,7 +14,7 @@ public class DetermineElectoralDistrictHandler(IGeocoderApiService geocoderApiSe : ILocalEventHandler, ITransientDependency { /// - /// Determines the Electoral Distrct based on the Address. + /// Determines the Electoral District based on the Address. /// /// /// @@ -30,31 +30,39 @@ public async Task HandleEventAsync(ApplicationProcessEvent eventData) if (eventData.FormVersion == null) { - logger.LogWarning("Application data is null in DetermineElectoralDistrictHandler."); + logger.LogWarning("Form version data is null in DetermineElectoralDistrictHandler."); return; } // Check if the electoral district is already mapped for the form submission, if so then no work to be done if (eventData.FormVersion.HasSubmissionHeaderMapping("ApplicantElectoralDistrict")) + { + logger.LogInformation("Electoral district already determined for application {ApplicationId}. No further action required.", + eventData.Application.Id); return; + } + + // Use local variable to avoid modifying the entity property + var addressType = eventData.Application.ApplicationForm.ElectoralDistrictAddressType ?? GrantApplications.AddressType.PhysicalAddress; + logger.LogInformation("Using electoral district address type: {AddressType} for electoral determination", addressType); - var electoralDistrictAddressType = eventData.Application.ApplicationForm.ElectoralDistrictAddressType; var applicantAddresses = eventData.Application.Applicant.ApplicantAddresses; if (applicantAddresses == null || applicantAddresses.Count == 0) { - logger.LogWarning("Application data is null in DetermineElectoralDistrictHandler."); + logger.LogWarning("Applicant addresses are null or empty in DetermineElectoralDistrictHandler for application {ApplicationId}.", + eventData.Application.Id); return; } // Find the related address type var matchedAddressType = applicantAddresses - .FirstOrDefault(a => a.AddressType == electoralDistrictAddressType); + .FirstOrDefault(a => a.AddressType == addressType); if (matchedAddressType == null) { logger.LogWarning("No address of type {AddressType} found for application {ApplicationId}.", - electoralDistrictAddressType, eventData.Application.Id); + addressType, eventData.Application.Id); return; } diff --git a/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/ApplicantInfo/ApplicantInfoViewComponent.cs b/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/ApplicantInfo/ApplicantInfoViewComponent.cs index 705fb1bad..544ca9480 100644 --- a/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/ApplicantInfo/ApplicantInfoViewComponent.cs +++ b/applications/Unity.GrantManager/src/Unity.GrantManager.Web/Views/Shared/Components/ApplicantInfo/ApplicantInfoViewComponent.cs @@ -45,6 +45,8 @@ public async Task InvokeAsync(Guid applicationId, Guid app ContactInfo = ObjectMapper.Map(applicantInfoDto.ContactInfo ?? new ContactInfoDto()), SigningAuthority = ObjectMapper.Map(applicantInfoDto.SigningAuthority ?? new SigningAuthorityDto()), ApplicantElectoralAddressType = electoralDistrictAddressType, + // This is fixed at the applicant level, we need solution this wrt the recent address logic added below + ElectoralDistrict = applicantInfoDto.ElectoralDistrict }; viewModel.ApplicantSummary.ApplicantId = applicantInfoDto.ApplicantId;