Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Microsoft.Extensions.Logging;
using Unity.Payments.Integrations.Cas;
using Microsoft.Extensions.Logging.Abstractions;
using Unity.Payments.Suppliers;
using Unity.Payments.Domain.Suppliers;

namespace Unity.GrantManager.Applicants;

Expand All @@ -23,6 +25,7 @@ namespace Unity.GrantManager.Applicants;
[ExposeServices(typeof(ApplicantAppService), typeof(IApplicantAppService))]
public class ApplicantAppService(IApplicantRepository applicantRepository,
ISupplierService supplierService,
ISiteAppService siteAppService,
IApplicantAddressRepository addressRepository,
IOrgBookService orgBookService,
IApplicantAgentRepository applicantAgentRepository) : GrantManagerAppService, IApplicantAppService
Expand Down Expand Up @@ -65,6 +68,17 @@ public async Task<Applicant> RelateSupplierToApplicant(ApplicantSupplierEto appl
Applicant? applicant = await applicantRepository.GetAsync(applicantSupplierEto.ApplicantId);
ArgumentNullException.ThrowIfNull(applicant);
applicant.SupplierId = applicantSupplierEto.SupplierId;
applicant.SiteId = null; // Reset site id to null
// lookup sites if there is only one then set it as default
if (applicant.SupplierId != null)
{
List<Site> sites = await siteAppService.GetSitesBySupplierIdAsync(applicant.SupplierId.Value);
if (sites.Count == 1)
{
applicant.SiteId = sites.FirstOrDefault()?.Id;
}
}

await applicantRepository.UpdateAsync(applicant);
return applicant;
}
Expand Down