Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public async Task<GrantApplicationDto> 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<UpdateApplicantInfoDto, Applications.Application>(input.Data, application);

//-- APPLICANT INFO - SUMMARY
Expand Down Expand Up @@ -190,6 +191,14 @@ public async Task<GrantApplicationDto> 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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public GrantManagerApplicationAutoMapperProfile()
CreateMap<UpdateApplicantInfoDto, Applicant>()
.IgnoreNullAndDefaultValues();
CreateMap<UpdateApplicantInfoDto, Application>()
.IgnoreNullAndDefaultValues();
.IgnoreNullAndDefaultValues()
.ForMember(dest => dest.ElectoralDistrict, opt => opt.Ignore()); // Electoral district is handled separately
CreateMap<SigningAuthorityDto, Application>()
.IgnoreNullAndDefaultValues();
CreateMap<UpdateApplicantSummaryDto, Applicant>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DetermineElectoralDistrictHandler(IGeocoderApiService geocoderApiSe
: ILocalEventHandler<ApplicationProcessEvent>, ITransientDependency
{
/// <summary>
/// Determines the Electoral Distrct based on the Address.
/// Determines the Electoral District based on the Address.
/// </summary>
/// <param name="eventData"></param>
/// <returns></returns>
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public async Task<IViewComponentResult> InvokeAsync(Guid applicationId, Guid app
ContactInfo = ObjectMapper.Map<ContactInfoDto, ContactInfoViewModel>(applicantInfoDto.ContactInfo ?? new ContactInfoDto()),
SigningAuthority = ObjectMapper.Map<SigningAuthorityDto, SigningAuthorityViewModel>(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;
Expand Down