Skip to content

Commit 57c328e

Browse files
authored
Merge pull request #1622 from bcgov/dev
Dev
2 parents d615ae5 + d53da5a commit 57c328e

1 file changed

Lines changed: 45 additions & 41 deletions

File tree

applications/Unity.GrantManager/src/Unity.GrantManager.Application/GrantApplications/GrantApplicationAppService.cs

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,17 @@ public async Task<PagedResultDto<GrantApplicationDto>> GetListAsync(PagedAndSort
154154

155155
return appDto;
156156
}).ToList();
157-
157+
158158
long totalCount = 0;
159159
try
160160
{
161161
totalCount = await _applicationRepository.GetCountAsync();
162-
} catch(Exception ex)
162+
}
163+
catch (Exception ex)
163164
{
164165
Logger.LogError(ex, "An exception occurred GetCountAsync: {ExceptionMessage}", ex.Message);
165166
}
166-
167+
167168
return new PagedResultDto<GrantApplicationDto>(totalCount, appDtos);
168169
}
169170

@@ -251,7 +252,7 @@ public async Task<GrantApplicationDto> GetAsync(Guid id)
251252
appDto.Sector = application.Applicant.Sector;
252253
appDto.OrganizationType = application.Applicant.OrganizationType;
253254
appDto.SubSector = application.Applicant.SubSector;
254-
appDto.SectorSubSectorIndustryDesc = application.Applicant.SectorSubSectorIndustryDesc;
255+
appDto.SectorSubSectorIndustryDesc = application.Applicant.SectorSubSectorIndustryDesc;
255256
}
256257

257258
return appDto;
@@ -598,56 +599,59 @@ public async Task<GrantApplicationDto> UpdatePartialProjectInfoAsync(Guid id, Pa
598599
return ObjectMapper.Map<Application, GrantApplicationDto>(application);
599600
}
600601

602+
private static bool HasValue(JsonElement element)
603+
{
604+
return element.ValueKind switch
605+
{
606+
JsonValueKind.Object => element.EnumerateObject().Any(),
607+
JsonValueKind.Array => element.EnumerateArray().Any(),
608+
JsonValueKind.String => !string.IsNullOrWhiteSpace(element.GetString()),
609+
JsonValueKind.Number => true,
610+
JsonValueKind.True => true,
611+
JsonValueKind.False => true,
612+
_ => false
613+
};
614+
}
601615
public async Task<GrantApplicationDto> UpdateFundingAgreementInfoAsync(Guid id, CreateUpdateFundingAgreementInfoDto input)
602616
{
603617
var application = await _applicationRepository.GetAsync(id);
604618

605-
if (application != null)
619+
// Update simple fields
620+
if (application.ContractNumber != input.ContractNumber ||
621+
application.ContractExecutionDate != input.ContractExecutionDate)
606622
{
607623
application.ContractNumber = input.ContractNumber;
608624
application.ContractExecutionDate = input.ContractExecutionDate;
625+
}
609626

610-
// Handle custom fields for funding agreement info
611-
if (input.CustomFields != null && HasValue(input.CustomFields) && input.CorrelationId != Guid.Empty)
627+
// Handle custom fields
628+
if (HasValue(input.CustomFields) && input.CorrelationId != Guid.Empty)
629+
{
630+
if (input.WorksheetIds?.Count > 0)
612631
{
613-
// Handle multiple worksheets
614-
if (input.WorksheetIds?.Count > 0)
632+
foreach (var worksheetId in input.WorksheetIds)
615633
{
616-
foreach (var worksheetId in input.WorksheetIds)
634+
var worksheetCustomFields = ExtractCustomFieldsForWorksheet(input.CustomFields, worksheetId);
635+
if (worksheetCustomFields.Count > 0)
617636
{
618-
var worksheetCustomFields = ExtractCustomFieldsForWorksheet(input.CustomFields, worksheetId);
619-
if (worksheetCustomFields.Count > 0)
637+
var worksheetData = new CustomDataFieldDto
620638
{
621-
var worksheetData = new CustomDataFieldDto
622-
{
623-
WorksheetId = worksheetId,
624-
CustomFields = worksheetCustomFields,
625-
CorrelationId = input.CorrelationId
626-
};
627-
await PublishCustomFieldUpdatesAsync(application.Id, FlexConsts.FundingAgreementInfoUiAnchor, worksheetData);
628-
}
639+
WorksheetId = worksheetId,
640+
CustomFields = worksheetCustomFields,
641+
CorrelationId = input.CorrelationId
642+
};
643+
await PublishCustomFieldUpdatesAsync(application.Id, FlexConsts.FundingAgreementInfoUiAnchor, worksheetData);
629644
}
630645
}
631-
// Fallback for single worksheet (backward compatibility)
632-
else if (input.WorksheetId != Guid.Empty)
633-
{
634-
await PublishCustomFieldUpdatesAsync(application.Id, FlexConsts.FundingAgreementInfoUiAnchor, input);
635-
}
636646
}
637-
638-
await _applicationRepository.UpdateAsync(application);
639-
640-
return ObjectMapper.Map<Application, GrantApplicationDto>(application);
641-
}
642-
else
643-
{
644-
throw new EntityNotFoundException();
647+
else if (input.WorksheetId != Guid.Empty) // backward compatibility
648+
{
649+
await PublishCustomFieldUpdatesAsync(application.Id, FlexConsts.FundingAgreementInfoUiAnchor, input);
650+
}
645651
}
646-
}
647652

648-
private static bool HasValue(JsonElement element)
649-
{
650-
return element.ValueKind != JsonValueKind.Null && element.ValueKind != JsonValueKind.Undefined;
653+
await _applicationRepository.UpdateAsync(application);
654+
return ObjectMapper.Map<Application, GrantApplicationDto>(application);
651655
}
652656

653657
/// <summary>
@@ -683,7 +687,7 @@ public async Task UpdateSupplierNumberAsync(Guid applicationId, string supplierN
683687
.FirstOrDefaultAsync(a => a.ApplicantId == application.ApplicantId)
684688
?? new ApplicantAgent
685689
{
686-
ApplicantId = application.ApplicantId,
690+
ApplicantId = application.ApplicantId,
687691
ApplicationId = application.Id
688692
};
689693

@@ -706,10 +710,10 @@ public async Task UpdateSupplierNumberAsync(Guid applicationId, string supplierN
706710
public async Task<GrantApplicationDto> UpdateProjectApplicantInfoAsync(Guid id, CreateUpdateApplicantInfoDto input)
707711
{
708712
var application = await _applicationRepository.GetAsync(id);
709-
713+
710714
var applicant = await _applicantRepository
711715
.FirstOrDefaultAsync(a => a.Id == application.ApplicantId) ?? throw new EntityNotFoundException();
712-
716+
713717
applicant.OrganizationType = input.OrganizationType ?? "";
714718
applicant.OrgName = input.OrgName ?? "";
715719
applicant.OrgNumber = input.OrgNumber ?? "";
@@ -1143,7 +1147,7 @@ public async Task<ApplicationStatusDto> GetApplicationStatusAsync(Guid id)
11431147
{
11441148
return null;
11451149
}
1146-
1150+
11471151
return form.AccountCodingId;
11481152
}
11491153

0 commit comments

Comments
 (0)