diff --git a/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs b/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs index 970c73348..1dbb6039a 100644 --- a/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs +++ b/src/Spd.Resource.Repository/BizLicApplication/BizLicApplicationRepository.cs @@ -62,6 +62,7 @@ public async Task CreateBizLicApplicationAsync(CreateB await SetInfoFromBiz(biz, app, cmd.ApplicantIsBizManager ?? false, ct); await SetOwner(app, Guid.Parse(DynamicsConstants.Licensing_Client_Service_Team_Guid), ct); + await SetApplicantSwlLicenceId(app, cmd.ApplicantSwlLicenceId, ct); SharedRepositoryFuncs.LinkServiceType(_context, cmd.ServiceTypeCode, app); SharedRepositoryFuncs.LinkSubmittedByPortalUser(_context, cmd.SubmittedByPortalUserId, app); @@ -114,16 +115,7 @@ public async Task SaveBizLicApplicationAsync(SaveBizLi else _context.SetLink(app, nameof(app.spd_CurrentExpiredLicenceId), null); - if (cmd.ApplicantSwlLicenceId != null) - { - var licence = _context.spd_licences.Where(l => l.spd_licenceid == cmd.ApplicantSwlLicenceId).FirstOrDefault(); - if (licence != null) - { - _context.SetLink(app, nameof(spd_application.spd_ApplicantSWLNumberId), licence); - } - } - else - _context.SetLink(app, nameof(app.spd_ApplicantSWLNumberId), null); + await SetApplicantSwlLicenceId(app, cmd.ApplicantSwlLicenceId, ct); SharedRepositoryFuncs.LinkSubmittedByPortalUser(_context, cmd.SubmittedByPortalUserId, app); @@ -287,6 +279,20 @@ private async Task UpsertPrivateInvestigator(PrivateInvesti return bizContact; } + private async Task SetApplicantSwlLicenceId(spd_application app, Guid? applicantSwlLicenceId, CancellationToken ct) + { + if (applicantSwlLicenceId != null) + { + var licence = await _context.spd_licences.Where(l => l.spd_licenceid == applicantSwlLicenceId).FirstOrDefaultAsync(ct); + if (licence != null) + { + _context.SetLink(app, nameof(spd_application.spd_ApplicantSWLNumberId), licence); + } + } + else + _context.SetLink(app, nameof(app.spd_ApplicantSWLNumberId), null); + } + private void AddPrivateInvestigatorLink(spd_businesscontact bizContact, spd_application app) { _context.AddLink(bizContact, nameof(spd_application.spd_businesscontact_spd_application), app);