diff --git a/src/Employer/Employer.Web/Controllers/LegalEntityAgreementController.cs b/src/Employer/Employer.Web/Controllers/LegalEntityAgreementController.cs index 32d228a64a..2f848cc3be 100644 --- a/src/Employer/Employer.Web/Controllers/LegalEntityAgreementController.cs +++ b/src/Employer/Employer.Web/Controllers/LegalEntityAgreementController.cs @@ -24,7 +24,7 @@ public LegalEntityAgreementController( public async Task LegalEntityAgreementSoftStop(VacancyRouteModel vrm, [FromQuery] string wizard = "true") { var info = GetVacancyEmployerInfoCookie(vrm.VacancyId); - var vm = await _orchestrator.GetLegalEntityAgreementSoftStopViewModelAsync(vrm, info.LegalEntityId); + var vm = await _orchestrator.GetLegalEntityAgreementSoftStopViewModelAsync(vrm, info.AccountLegalEntityPublicHashedId); vm.PageInfo.SetWizard(wizard); if (vm.HasLegalEntityAgreement == false) diff --git a/src/Employer/Employer.Web/Controllers/Part1/EmployerController.cs b/src/Employer/Employer.Web/Controllers/Part1/EmployerController.cs index 80f925eb7a..2e4f5f5be7 100644 --- a/src/Employer/Employer.Web/Controllers/Part1/EmployerController.cs +++ b/src/Employer/Employer.Web/Controllers/Part1/EmployerController.cs @@ -25,15 +25,15 @@ public async Task Employer(VacancyRouteModel vrm, [FromQuery]stri { var info = GetVacancyEmployerInfoCookie(vrm.VacancyId); - var vm = await _orchestrator.GetEmployerViewModelAsync(vrm, searchTerm, page, info?.LegalEntityId); + var vm = await _orchestrator.GetEmployerViewModelAsync(vrm, searchTerm, page, info?.AccountLegalEntityPublicHashedId); - if (info == null || !info.LegalEntityId.HasValue) + if (info == null || !string.IsNullOrEmpty(info.AccountLegalEntityPublicHashedId)) { SetVacancyEmployerInfoCookie(vm.VacancyEmployerInfoModel); } else { - vm.SelectedOrganisationId = info.LegalEntityId; + vm.SelectedOrganisationId = info.AccountLegalEntityPublicHashedId; } if (vm.HasOnlyOneOrganisation) @@ -60,16 +60,16 @@ public async Task Employer(EmployerEditModel m, [FromQuery] bool if (!ModelState.IsValid) { - var vm = await _orchestrator.GetEmployerViewModelAsync(m, m.SearchTerm, m.Page, info?.LegalEntityId); + var vm = await _orchestrator.GetEmployerViewModelAsync(m, m.SearchTerm, m.Page, info?.AccountLegalEntityPublicHashedId); SetVacancyEmployerInfoCookie(vm.VacancyEmployerInfoModel); vm.Pager.OtherRouteValues.Add(nameof(wizard), wizard.ToString()); vm.PageInfo.SetWizard(wizard); return View(vm); } - if (info.LegalEntityId != m.SelectedOrganisationId) + if (info.AccountLegalEntityPublicHashedId != m.SelectedOrganisationId) { - info.LegalEntityId = m.SelectedOrganisationId; + info.AccountLegalEntityPublicHashedId = m.SelectedOrganisationId; info.HasLegalEntityChanged = true; info.EmployerIdentityOption = null; info.NewTradingName = null; diff --git a/src/Employer/Employer.Web/Models/VacancyEmployerInfoModel.cs b/src/Employer/Employer.Web/Models/VacancyEmployerInfoModel.cs index 0d1491faad..e7f05ba70e 100644 --- a/src/Employer/Employer.Web/Models/VacancyEmployerInfoModel.cs +++ b/src/Employer/Employer.Web/Models/VacancyEmployerInfoModel.cs @@ -1,5 +1,4 @@ using System; -using Esfa.Recruit.Employer.Web.ViewModels.Part1.EmployerName; using Esfa.Recruit.Shared.Web.Models; namespace Esfa.Recruit.Employer.Web.Models @@ -7,11 +6,11 @@ namespace Esfa.Recruit.Employer.Web.Models public class VacancyEmployerInfoModel { public Guid? VacancyId { get; set; } - public long? LegalEntityId { get; set; } public EmployerIdentityOption? EmployerIdentityOption { get; set; } public string NewTradingName { get; set; } public bool HasLegalEntityChanged { get; set;} public string AnonymousName { get; set; } public string AnonymousReason { get; set; } + public string AccountLegalEntityPublicHashedId { get; set; } } } \ No newline at end of file diff --git a/src/Employer/Employer.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs index 167a61d520..59fdbeafef 100644 --- a/src/Employer/Employer.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs @@ -25,16 +25,16 @@ public LegalEntityAgreementOrchestrator( } public async Task GetLegalEntityAgreementSoftStopViewModelAsync( - VacancyRouteModel vrm, long? selectedLegalEntityId) + VacancyRouteModel vrm, string selectedAccountLegalEntityPublicHashedId) { var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _client, _vacancyClient, vrm, RouteNames.LegalEntityAgreement_SoftStop_Get); - var legalEntityId = selectedLegalEntityId.HasValue ? selectedLegalEntityId.Value : vacancy.LegalEntityId; + var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId) ? selectedAccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId; LegalEntity legalEntity = await - _legalEntityAgreementService.GetLegalEntityAsync(vrm.EmployerAccountId, legalEntityId); + _legalEntityAgreementService.GetLegalEntityAsync(vrm.EmployerAccountId, accountLegalEntityPublicHashedId); var hasLegalEntityAgreement = await _legalEntityAgreementService.HasLegalEntityAgreementAsync( @@ -56,7 +56,7 @@ public async Task GetLegalEntityAgreement return new LegalEntityAgreementHardStopViewModel { HasLegalEntityAgreement = await _legalEntityAgreementService.HasLegalEntityAgreementAsync( - vacancy.EmployerAccountId, vacancy.LegalEntityId) + vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId) }; } } diff --git a/src/Employer/Employer.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs index 860a7895a5..19915a7e92 100644 --- a/src/Employer/Employer.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs @@ -42,15 +42,15 @@ public async Task GetEmployerNameViewModelAsync( var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _employerVacancyClient, _recruitVacancyClient, vrm, RouteNames.Employer_Get); - var legalEntityId = employerInfoModel.LegalEntityId.GetValueOrDefault(); + var accountLegalEntityPublicHashedId = employerInfoModel.AccountLegalEntityPublicHashedId; var getEmployerDataTask = _employerVacancyClient.GetEditVacancyInfoAsync(vrm.EmployerAccountId); - var getEmployerProfileTask = _recruitVacancyClient.GetEmployerProfileAsync(vrm.EmployerAccountId, legalEntityId); + var getEmployerProfileTask = _recruitVacancyClient.GetEmployerProfileAsync(vrm.EmployerAccountId, accountLegalEntityPublicHashedId); await Task.WhenAll(getEmployerDataTask, getEmployerProfileTask); var editVacancyInfo = getEmployerDataTask.Result; var employerProfile = getEmployerProfileTask.Result; - var legalEntity = editVacancyInfo.LegalEntities.Single(l => l.LegalEntityId == legalEntityId); + var legalEntity = editVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var vm = new EmployerNameViewModel { diff --git a/src/Employer/Employer.Web/Orchestrators/Part1/EmployerOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/Part1/EmployerOrchestrator.cs index 4c60ac7b83..ca1331bb58 100644 --- a/src/Employer/Employer.Web/Orchestrators/Part1/EmployerOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/Part1/EmployerOrchestrator.cs @@ -33,7 +33,7 @@ public EmployerOrchestrator( _logger = logger; } - public async Task GetEmployerViewModelAsync(VacancyRouteModel vrm, string searchTerm, int? requestedPageNo, long? selectedLegalEntityId = 0) + public async Task GetEmployerViewModelAsync(VacancyRouteModel vrm, string searchTerm, int? requestedPageNo, string selectedAccountLegalEntityPublicHashedId) { const int NotFoundIndex = -1; var setPage = requestedPageNo.HasValue ? requestedPageNo.Value : 1; @@ -49,17 +49,17 @@ public async Task GetEmployerViewModelAsync(VacancyRouteModel var vm = new EmployerViewModel { TotalNumberOfLegalEntities = legalEntities.Count(), - SelectedOrganisationId = vacancy.LegalEntityId, PageInfo = Utility.GetPartOnePageInfo(vacancy), - SearchTerm = searchTerm + SearchTerm = searchTerm, + SelectedOrganisationId = vacancy.AccountLegalEntityPublicHashedId }; - if (vacancy.LegalEntityId != 0 && (selectedLegalEntityId.HasValue == false || selectedLegalEntityId == 0)) + if (!string.IsNullOrEmpty(vacancy.AccountLegalEntityPublicHashedId) && string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId)) { - selectedLegalEntityId = vacancy.LegalEntityId; + selectedAccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId; } - vm.IsPreviouslySelectedLegalEntityStillValid = selectedLegalEntityId.HasValue && legalEntities.Any(le => le.Id == selectedLegalEntityId); + vm.IsPreviouslySelectedLegalEntityStillValid = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId) && legalEntities.Any(le => le.Id == selectedAccountLegalEntityPublicHashedId); var filteredLegalEntities = legalEntities .Where(le => string.IsNullOrEmpty(searchTerm) || le.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)) @@ -69,8 +69,8 @@ public async Task GetEmployerViewModelAsync(VacancyRouteModel var filteredLegalEntitiesTotal = filteredLegalEntities.Count(); var totalNumberOfPages = PagingHelper.GetTotalNoOfPages(MaxLegalEntitiesPerPage, filteredLegalEntitiesTotal); - var indexOfSelectedLegalEntity = selectedLegalEntityId.HasValue - ? filteredLegalEntities.FindIndex(le => le.Id == selectedLegalEntityId.Value) + 1 + var indexOfSelectedLegalEntity = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId) + ? filteredLegalEntities.FindIndex(le => le.Id == selectedAccountLegalEntityPublicHashedId) + 1 : NotFoundIndex; setPage = GetPageNo(requestedPageNo, setPage, totalNumberOfPages, indexOfSelectedLegalEntity); @@ -82,12 +82,12 @@ public async Task GetEmployerViewModelAsync(VacancyRouteModel vm.VacancyEmployerInfoModel = new VacancyEmployerInfoModel() { VacancyId = vacancy.Id, - LegalEntityId = vacancy.LegalEntityId == 0 ? (long?)null : vacancy.LegalEntityId + AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId }; - if (vm.VacancyEmployerInfoModel.LegalEntityId == null && vm.HasOnlyOneOrganisation) + if (vm.VacancyEmployerInfoModel.AccountLegalEntityPublicHashedId == null && vm.HasOnlyOneOrganisation) { - vm.VacancyEmployerInfoModel.LegalEntityId = vm.Organisations.First().Id; + vm.VacancyEmployerInfoModel.AccountLegalEntityPublicHashedId = vm.Organisations.First().Id; } if (vacancy.EmployerNameOption.HasValue) @@ -148,7 +148,7 @@ private IEnumerable BuildLegalEntityViewModels(EmployerEd private OrganisationViewModel ConvertToOrganisationViewModel(LegalEntity data) { - return new OrganisationViewModel { Id = data.LegalEntityId, Name = data.Name}; + return new OrganisationViewModel { Id = data.AccountLegalEntityPublicHashedId, Name = data.Name}; } } } \ No newline at end of file diff --git a/src/Employer/Employer.Web/Orchestrators/Part1/LocationOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/Part1/LocationOrchestrator.cs index daf150a155..312511c11f 100644 --- a/src/Employer/Employer.Web/Orchestrators/Part1/LocationOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/Part1/LocationOrchestrator.cs @@ -44,7 +44,7 @@ public async Task GetVacancyEmployerInfoModelAsync(Vac var model = new VacancyEmployerInfoModel() { VacancyId = vacancy.Id, - LegalEntityId = vacancy.LegalEntityId == 0 ? (long?) null : vacancy.LegalEntityId + AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId }; if (vacancy.EmployerNameOption.HasValue) @@ -63,7 +63,9 @@ public async Task GetLocationViewModelAsync( var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_employerVacancyClient, _recruitVacancyClient, vrm, RouteNames.Location_Get); - var legalEntityId = employerInfoModel?.LegalEntityId != null ? employerInfoModel.LegalEntityId : vacancy.LegalEntityId; + var accountLegalEntityPublicHashedId = employerInfoModel?.AccountLegalEntityPublicHashedId != null + ? employerInfoModel.AccountLegalEntityPublicHashedId + : vacancy.AccountLegalEntityPublicHashedId; var vm = new LocationViewModel(); vm.PageInfo = Utility.GetPartOnePageInfo(vacancy); @@ -73,7 +75,7 @@ public async Task GetLocationViewModelAsync( : employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.Anonymous; var employerProfile = - await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, legalEntityId.GetValueOrDefault()); + await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile); @@ -119,12 +121,15 @@ public async Task PostLocationEditModelAsync( var vacancy = vacancyTask.Result; var editVacancyInfo = employerVacancyInfoTask.Result; - var legalEntityId = employerInfoModel?.LegalEntityId == null ? vacancy.LegalEntityId : employerInfoModel.LegalEntityId; + var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId) + ? employerInfoModel.AccountLegalEntityPublicHashedId + : vacancy.AccountLegalEntityPublicHashedId; + var selectedOrganisation = - editVacancyInfo.LegalEntities.Single(l => l.LegalEntityId == legalEntityId); + editVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var employerProfile = - await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, selectedOrganisation.LegalEntityId); + await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, selectedOrganisation.AccountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile); @@ -142,7 +147,6 @@ public async Task PostLocationEditModelAsync( { vacancy.LegalEntityName = selectedOrganisation.Name; vacancy.AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId; - vacancy.LegalEntityId = employerInfoModel.LegalEntityId.GetValueOrDefault(); vacancy.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption(); vacancy.AnonymousReason = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null; vacancy.EmployerName = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null; @@ -181,6 +185,11 @@ private async Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoMo EmployerProfile employerProfile, Address address, VacancyUser user) { var updateProfile = false; + if (string.IsNullOrEmpty(employerProfile.AccountLegalEntityPublicHashedId) && !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId)) + { + updateProfile = true; + employerProfile.AccountLegalEntityPublicHashedId = employerInfoModel.AccountLegalEntityPublicHashedId; + } if (employerInfoModel != null && employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.NewTradingName) { updateProfile = true; @@ -202,7 +211,7 @@ private async Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoMo private async Task> GetAllAvailableLocationsAsync(EmployerProfile employerProfile) { var employerData = await _employerVacancyClient.GetEditVacancyInfoAsync(employerProfile.EmployerAccountId); - var legalEntity = employerData.LegalEntities.First(l => l.LegalEntityId == employerProfile.LegalEntityId); + var legalEntity = employerData.LegalEntities.First(l => l.AccountLegalEntityPublicHashedId == employerProfile.AccountLegalEntityPublicHashedId); var locations = new List
(); locations.Add(legalEntity.Address.ConvertToDomainAddress()); diff --git a/src/Employer/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestrator.cs index 28c5cbbf1f..2d9aa7cdb3 100644 --- a/src/Employer/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/Part2/AboutEmployerOrchestrator.cs @@ -82,11 +82,12 @@ public async Task PostAboutEmployerEditModelAsync(AboutEmp private async Task UpdateEmployerProfileAsync(Vacancy vacancy, string employerDescription, VacancyUser user) { var employerProfile = - await _vacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, vacancy.LegalEntityId); + await _vacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId); if (employerProfile == null) { - throw new NullReferenceException($"No Employer Profile was found for employerAccount: {vacancy.EmployerAccountId}, legalEntity: {vacancy.LegalEntityId}"); + throw new NullReferenceException($"No Employer Profile was found for employerAccount: {vacancy.EmployerAccountId}, " + + $"accountLegalEntityPublicHashedId : {vacancy.AccountLegalEntityPublicHashedId}"); } if (employerProfile.AboutOrganisation != employerDescription) diff --git a/src/Employer/Employer.Web/Orchestrators/VacancyPreviewOrchestrator.cs b/src/Employer/Employer.Web/Orchestrators/VacancyPreviewOrchestrator.cs index 33c2ba1879..adae7d40ca 100644 --- a/src/Employer/Employer.Web/Orchestrators/VacancyPreviewOrchestrator.cs +++ b/src/Employer/Employer.Web/Orchestrators/VacancyPreviewOrchestrator.cs @@ -115,7 +115,7 @@ private async Task SubmitActionAsync(Vacancy vacancy, Vac { var response = new SubmitVacancyResponse { - HasLegalEntityAgreement = await _legalEntityAgreementService.HasLegalEntityAgreementAsync(vacancy.EmployerAccountId, vacancy.LegalEntityId), + HasLegalEntityAgreement = await _legalEntityAgreementService.HasLegalEntityAgreementAsync(vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId), IsSubmitted = false }; diff --git a/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerEditModel.cs b/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerEditModel.cs index 1bc09ee0e9..568ed94dc2 100644 --- a/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerEditModel.cs +++ b/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerEditModel.cs @@ -1,14 +1,12 @@ using System.ComponentModel.DataAnnotations; using Esfa.Recruit.Employer.Web.RouteModel; -using Esfa.Recruit.Employer.Web.ViewModels; namespace Esfa.Recruit.Employer.Web.ViewModels.Part1.Employer { public class EmployerEditModel : VacancyRouteModel { [Required(ErrorMessage = ValidationMessages.EmployerSelectionValidationMessages.EmployerSelectionRequired)] - public long? SelectedOrganisationId { get; set; } - + public string SelectedOrganisationId { get; set; } public string SearchTerm { get; set; } public int Page { get; set; } } diff --git a/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerViewModel.cs b/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerViewModel.cs index 4c2d489800..c2e05f9037 100644 --- a/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerViewModel.cs +++ b/src/Employer/Employer.Web/ViewModels/Part1/Employer/EmployerViewModel.cs @@ -17,13 +17,12 @@ public class EmployerViewModel : VacancyRouteModel public PartOnePageInfoViewModel PageInfo { get; internal set; } public PagerViewModel Pager { get; internal set; } - public IList OrderedFieldNames => new List { - nameof(SelectedOrganisationId) + nameof(SelectedOrganisationId ) }; - public long? SelectedOrganisationId { get; internal set; } + public string SelectedOrganisationId { get; internal set; } public VacancyEmployerInfoModel VacancyEmployerInfoModel { get; internal set; } @@ -38,18 +37,18 @@ public class EmployerViewModel : VacancyRouteModel public int TotalNumberOfLegalEntities { get; internal set; } public bool IsPreviouslySelectedLegalEntityStillValid { get; internal set; } - public bool HasPreviouslyPersistedLegalEntity => SelectedOrganisationId.Value > 0; + public bool HasPreviouslyPersistedLegalEntity => !string.IsNullOrEmpty(SelectedOrganisationId); public bool IsSelectedOrganisationInPagedOrganisations => IsPreviouslySelectedLegalEntityStillValid && HasPreviouslyPersistedLegalEntity - && Organisations.Any(org => org.Id == SelectedOrganisationId.Value); + && Organisations.Any(org => org.Id == SelectedOrganisationId); - public bool CanOutputHiddenSelectedOrganisationIdField => SelectedOrganisationId.Value > 0 && IsSelectedOrganisationInPagedOrganisations == false; + public bool CanOutputHiddenSelectedOrganisationIdField => !string.IsNullOrEmpty(SelectedOrganisationId) && IsSelectedOrganisationInPagedOrganisations == false; } public class OrganisationViewModel { - public long Id { get; set; } + public string Id { get; set; } public string Name { get; set; } } } diff --git a/src/Employer/UnitTests/Employer.Web/Services/LegalEntityAgreementServiceTests.cs b/src/Employer/UnitTests/Employer.Web/Services/LegalEntityAgreementServiceTests.cs index d6a163a523..b7f0fffcb6 100644 --- a/src/Employer/UnitTests/Employer.Web/Services/LegalEntityAgreementServiceTests.cs +++ b/src/Employer/UnitTests/Employer.Web/Services/LegalEntityAgreementServiceTests.cs @@ -14,15 +14,16 @@ public class LegalEntityAgreementServiceTests { const string EmployerAccountId = "ABCDEF"; const long LegalEntityId = 1234; + const string AccountLegalEntityPublicHashedId = "ABCDEF"; private Mock _clientMock; [Fact] public void HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLegalEntity() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, 5678, true, 5678, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, 5678, true, 5678, true, "5678"); - var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; + var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result; result.Should().BeFalse(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Never); @@ -31,30 +32,32 @@ public void HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLegalEntit [Fact] public void HasLegalEntityAgreementAsync_ShouldNotCheckEmployerServiceWhenHasAgreement() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, true, LegalEntityId, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, true, LegalEntityId, true, AccountLegalEntityPublicHashedId); - var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; + var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result; result.Should().BeTrue(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Never); } - [Fact] public void HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHasNoAgreement() + [Fact] + public void HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHasNoAgreement() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, true, AccountLegalEntityPublicHashedId); - var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; + var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result; result.Should().BeTrue(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); _clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Once); } - [Fact] public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceLegalEntityHasNoAgreement() + [Fact] + public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceLegalEntityHasNoAgreement() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, false); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, false, AccountLegalEntityPublicHashedId); - var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; + var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result; result.Should().BeFalse(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); @@ -64,16 +67,18 @@ [Fact] public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerSer [Fact] public void HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceCantLocateLegalEntity() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, 5678, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, 5678, true, AccountLegalEntityPublicHashedId); - var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId).Result; + var result = sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId).Result; result.Should().BeFalse(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); _clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Never); } - private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId, long legalEntityId, bool hasLegalEntityAgreement, long employerServiceLegalEntityId, bool employerServiceHasLegalEntityAgreement) + private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId, long legalEntityId, + bool hasLegalEntityAgreement, long employerServiceLegalEntityId, + bool employerServiceHasLegalEntityAgreement, string accountLegalEntityPublicHashedId) { _clientMock = new Mock(); _clientMock.Setup(c => c.GetEditVacancyInfoAsync(employerAccountId)).Returns(Task.FromResult( @@ -81,7 +86,11 @@ private LegalEntityAgreementService GetLegalEntityAgreementService(string employ { LegalEntities = new List { - new LegalEntity{LegalEntityId = legalEntityId, HasLegalEntityAgreement = hasLegalEntityAgreement} + new LegalEntity{ + LegalEntityId = legalEntityId, + HasLegalEntityAgreement = hasLegalEntityAgreement, + AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId + } } })); @@ -90,8 +99,8 @@ private LegalEntityAgreementService GetLegalEntityAgreementService(string employ { new LegalEntity { - LegalEntityId = employerServiceLegalEntityId, - HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement + LegalEntityId = employerServiceLegalEntityId, + HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement } } .AsEnumerable())); diff --git a/src/Jobs/Recruit.Vacancies.Jobs/DomainEvents/Handlers/Employer/SetupEmployerHandler.cs b/src/Jobs/Recruit.Vacancies.Jobs/DomainEvents/Handlers/Employer/SetupEmployerHandler.cs index fb8e57c920..ba0c2de054 100644 --- a/src/Jobs/Recruit.Vacancies.Jobs/DomainEvents/Handlers/Employer/SetupEmployerHandler.cs +++ b/src/Jobs/Recruit.Vacancies.Jobs/DomainEvents/Handlers/Employer/SetupEmployerHandler.cs @@ -33,7 +33,7 @@ public async Task HandleAsync(string eventPayload) var vacancyDataTask = _projectionService.UpdateEmployerVacancyDataAsync(@event.EmployerAccountId, legalEntities); - var employerProfilesTask = _client.RefreshEmployerProfiles(@event.EmployerAccountId, legalEntities.Select(x => x.LegalEntityId)); + var employerProfilesTask = _client.RefreshEmployerProfiles(@event.EmployerAccountId, legalEntities.Select(x => x.AccountLegalEntityPublicHashedId)); await Task.WhenAll(vacancyDataTask, employerProfilesTask); diff --git a/src/Provider/Provider.Web/Controllers/Part1/LegalEntityController.cs b/src/Provider/Provider.Web/Controllers/Part1/LegalEntityController.cs index 5a695db390..0441bee8bd 100644 --- a/src/Provider/Provider.Web/Controllers/Part1/LegalEntityController.cs +++ b/src/Provider/Provider.Web/Controllers/Part1/LegalEntityController.cs @@ -26,15 +26,15 @@ public async Task LegalEntity(VacancyRouteModel vrm, [FromQuery]s { var info = GetVacancyEmployerInfoCookie(vrm.VacancyId.GetValueOrDefault()); - var vm = await _orchestrator.GetLegalEntityViewModelAsync(vrm, User.GetUkprn(), searchTerm, page, info?.LegalEntityId); + var vm = await _orchestrator.GetLegalEntityViewModelAsync(vrm, User.GetUkprn(), searchTerm, page, info?.AccountLegalEntityPublicHashedId); - if (info == null || !info.LegalEntityId.HasValue) + if (info == null || !string.IsNullOrEmpty(info.AccountLegalEntityPublicHashedId)) { SetVacancyEmployerInfoCookie(vm.VacancyEmployerInfoModel); } else { - vm.SelectedOrganisationId = info.LegalEntityId; + vm.SelectedOrganisationId = info.AccountLegalEntityPublicHashedId; } if (vm.HasOnlyOneOrganisation) @@ -61,16 +61,16 @@ public async Task LegalEntity(LegalEntityEditModel m, [FromQuery] if (!ModelState.IsValid) { - var vm = await _orchestrator.GetLegalEntityViewModelAsync(m, User.GetUkprn(), m.SearchTerm, m.Page, info.LegalEntityId); + var vm = await _orchestrator.GetLegalEntityViewModelAsync(m, User.GetUkprn(), m.SearchTerm, m.Page, info.AccountLegalEntityPublicHashedId); SetVacancyEmployerInfoCookie(vm.VacancyEmployerInfoModel); vm.Pager.OtherRouteValues.Add(nameof(wizard), wizard.ToString()); vm.PageInfo.SetWizard(wizard); return View(vm); } - if (info.LegalEntityId != m.SelectedOrganisationId) + if (info.AccountLegalEntityPublicHashedId != m.SelectedOrganisationId) { - info.LegalEntityId = m.SelectedOrganisationId; + info.AccountLegalEntityPublicHashedId = m.SelectedOrganisationId; info.HasLegalEntityChanged = true; info.EmployerIdentityOption = null; info.NewTradingName = null; diff --git a/src/Provider/Provider.Web/Models/VacancyEmployerInfoModel.cs b/src/Provider/Provider.Web/Models/VacancyEmployerInfoModel.cs index 54c18164c9..f7a5274fe7 100644 --- a/src/Provider/Provider.Web/Models/VacancyEmployerInfoModel.cs +++ b/src/Provider/Provider.Web/Models/VacancyEmployerInfoModel.cs @@ -6,7 +6,7 @@ namespace Esfa.Recruit.Provider.Web.Models public class VacancyEmployerInfoModel { public Guid? VacancyId { get; set; } - public long? LegalEntityId { get; set; } + public string AccountLegalEntityPublicHashedId { get; set; } public EmployerIdentityOption? EmployerIdentityOption { get; set; } public string NewTradingName { get; set; } public bool HasLegalEntityChanged { get; set;} diff --git a/src/Provider/Provider.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs b/src/Provider/Provider.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs index dbdf2caae7..626bcc94f5 100644 --- a/src/Provider/Provider.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs +++ b/src/Provider/Provider.Web/Orchestrators/LegalEntityAgreementOrchestrator.cs @@ -31,7 +31,7 @@ public async Task GetLegalEntityAgreement return new LegalEntityAgreementHardStopViewModel { HasLegalEntityAgreement = await _legalEntityAgreementService.HasLegalEntityAgreementAsync( - vacancy.EmployerAccountId, vacancy.LegalEntityId), + vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId), LegalEntityName = vacancy.LegalEntityName }; } diff --git a/src/Provider/Provider.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs b/src/Provider/Provider.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs index a177e99759..c0eb9b6920 100644 --- a/src/Provider/Provider.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs +++ b/src/Provider/Provider.Web/Orchestrators/Part1/EmployerNameOrchestrator.cs @@ -45,18 +45,18 @@ public async Task GetEmployerNameViewModelAsync( var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _providerVacancyClient, _recruitVacancyClient, vrm, RouteNames.EmployerName_Get); - var legalEntityId = employerInfoModel.LegalEntityId.GetValueOrDefault(); + var accountLegalEntityPublicHashedId = employerInfoModel.AccountLegalEntityPublicHashedId; var getVacancyEditInfoTask = _providerVacancyClient.GetProviderEditVacancyInfoAsync(vrm.Ukprn); - var getEmployerProfileTask = _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, legalEntityId); + var getEmployerProfileTask = _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId); await Task.WhenAll(getVacancyEditInfoTask, getEmployerProfileTask); var employerInfo = getVacancyEditInfoTask.Result.Employers.Single(e => e.EmployerAccountId == vacancy.EmployerAccountId); var employerProfile = getEmployerProfileTask.Result; - var legalEntity = employerInfo.LegalEntities.Single(l => l.LegalEntityId == legalEntityId); + var legalEntity = employerInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var vm = new EmployerNameViewModel { diff --git a/src/Provider/Provider.Web/Orchestrators/Part1/LegalEntityOrchestrator.cs b/src/Provider/Provider.Web/Orchestrators/Part1/LegalEntityOrchestrator.cs index d801ed87a2..8e289ecc02 100644 --- a/src/Provider/Provider.Web/Orchestrators/Part1/LegalEntityOrchestrator.cs +++ b/src/Provider/Provider.Web/Orchestrators/Part1/LegalEntityOrchestrator.cs @@ -33,7 +33,7 @@ public LegalEntityOrchestrator( _logger = logger; } - public async Task GetLegalEntityViewModelAsync(VacancyRouteModel vrm, long ukprn, string searchTerm, int? requestedPageNo, long? selectedLegalEntityId = 0) + public async Task GetLegalEntityViewModelAsync(VacancyRouteModel vrm, long ukprn, string searchTerm, int? requestedPageNo, string selectedAccountLegalEntityPublicHashedId) { const int NotFoundIndex = -1; var setPage = requestedPageNo.HasValue ? requestedPageNo.Value : 1; @@ -44,17 +44,17 @@ public async Task GetLegalEntityViewModelAsync(VacancyRout var vm = new LegalEntityViewModel { TotalNumberOfLegalEntities = legalEntities.Count(), - SelectedOrganisationId = vacancy.LegalEntityId, + SelectedOrganisationId = vacancy.AccountLegalEntityPublicHashedId, PageInfo = Utility.GetPartOnePageInfo(vacancy), SearchTerm = searchTerm }; - if (vacancy.LegalEntityId != 0 && (selectedLegalEntityId.HasValue == false || selectedLegalEntityId == 0)) + if (!string.IsNullOrEmpty(vacancy.AccountLegalEntityPublicHashedId) && string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId)) { - selectedLegalEntityId = vacancy.LegalEntityId; + selectedAccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId; } - vm.IsPreviouslySelectedLegalEntityStillValid = selectedLegalEntityId.HasValue && legalEntities.Any(le => le.Id == selectedLegalEntityId); + vm.IsPreviouslySelectedLegalEntityStillValid = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId) && legalEntities.Any(le => le.Id == selectedAccountLegalEntityPublicHashedId); var filteredLegalEntities = legalEntities .Where(le => string.IsNullOrEmpty(searchTerm) || le.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)) @@ -64,8 +64,8 @@ public async Task GetLegalEntityViewModelAsync(VacancyRout var filteredLegalEntitiesTotal = filteredLegalEntities.Count(); var totalNumberOfPages = PagingHelper.GetTotalNoOfPages(MaxLegalEntitiesPerPage, filteredLegalEntitiesTotal); - var indexOfSelectedLegalEntity = selectedLegalEntityId.HasValue - ? filteredLegalEntities.FindIndex(le => le.Id == selectedLegalEntityId.Value) + 1 + var indexOfSelectedLegalEntity = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId) + ? filteredLegalEntities.FindIndex(le => le.Id == selectedAccountLegalEntityPublicHashedId) + 1 : NotFoundIndex; setPage = GetPageNo(requestedPageNo, setPage, totalNumberOfPages, indexOfSelectedLegalEntity); @@ -76,12 +76,12 @@ public async Task GetLegalEntityViewModelAsync(VacancyRout vm.VacancyEmployerInfoModel = new VacancyEmployerInfoModel { VacancyId = vacancy.Id, - LegalEntityId = vacancy.LegalEntityId == 0 ? (long?)null : vacancy.LegalEntityId + AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId }; - if (vm.VacancyEmployerInfoModel.LegalEntityId == null && vm.HasOnlyOneOrganisation) + if (string.IsNullOrEmpty(vm.VacancyEmployerInfoModel.AccountLegalEntityPublicHashedId) && vm.HasOnlyOneOrganisation) { - vm.VacancyEmployerInfoModel.LegalEntityId = vm.Organisations.First().Id; + vm.VacancyEmployerInfoModel.AccountLegalEntityPublicHashedId = vm.Organisations.First().Id; } if (vacancy.EmployerNameOption.HasValue) @@ -131,7 +131,7 @@ private void SetFilteredOrganisationsForPage(int page, LegalEntityViewModel vm, private OrganisationViewModel ConvertToOrganisationViewModel(LegalEntity data) { - return new OrganisationViewModel { Id = data.LegalEntityId, Name = data.Name }; + return new OrganisationViewModel { Id = data.AccountLegalEntityPublicHashedId, Name = data.Name }; } private async Task> GetLegalEntityViewModelsAsync(long ukprn, string employerAccountId) diff --git a/src/Provider/Provider.Web/Orchestrators/Part1/LocationOrchestrator.cs b/src/Provider/Provider.Web/Orchestrators/Part1/LocationOrchestrator.cs index 59e2ea79b1..f1b2e0e71c 100644 --- a/src/Provider/Provider.Web/Orchestrators/Part1/LocationOrchestrator.cs +++ b/src/Provider/Provider.Web/Orchestrators/Part1/LocationOrchestrator.cs @@ -26,7 +26,7 @@ public class LocationOrchestrator : EntityValidatingOrchestrator logger, IReviewSummaryService reviewSummaryService) : base(logger) { @@ -40,9 +40,10 @@ public async Task GetVacancyEmployerInfoModelAsync(Vac var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _providerVacancyClient, _recruitVacancyClient, vrm, RouteNames.Location_Get); - var model = new VacancyEmployerInfoModel() { + var model = new VacancyEmployerInfoModel() + { VacancyId = vacancy.Id, - LegalEntityId = vacancy.LegalEntityId == 0 ? (long?)null : vacancy.LegalEntityId + AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId }; if (vacancy.EmployerNameOption.HasValue) @@ -51,7 +52,7 @@ public async Task GetVacancyEmployerInfoModelAsync(Vac model.AnonymousName = vacancy.IsAnonymous ? vacancy.EmployerName : null; model.AnonymousReason = vacancy.IsAnonymous ? vacancy.AnonymousReason : null; } - + return model; } @@ -61,8 +62,9 @@ public async Task GetLocationViewModelAsync( var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _providerVacancyClient, _recruitVacancyClient, vrm, RouteNames.Location_Get); - var legalEntityId = employerInfoModel?.LegalEntityId ?? vacancy.LegalEntityId; - + var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId) + ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId; + var vm = new LocationViewModel(); vm.PageInfo = Utility.GetPartOnePageInfo(vacancy); @@ -71,7 +73,7 @@ public async Task GetLocationViewModelAsync( : employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.Anonymous; var employerProfile = - await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, legalEntityId); + await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile, vacancy, vrm.Ukprn); @@ -110,15 +112,16 @@ public async Task PostLocationEditModelAsync( var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_providerVacancyClient, _recruitVacancyClient, locationEditModel, RouteNames.Location_Post); - var legalEntityId = employerInfoModel?.LegalEntityId ?? vacancy.LegalEntityId; + var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId) + ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId; var employerVacancyInfoTask = _providerVacancyClient.GetProviderEmployerVacancyDataAsync(ukprn, vacancy.EmployerAccountId); - var employerProfileTask = _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, legalEntityId); + var employerProfileTask = _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId); await Task.WhenAll(employerProfileTask, employerVacancyInfoTask); var employerVacancyInfo = employerVacancyInfoTask.Result; var employerProfile = employerProfileTask.Result; - var selectedOrganisation = employerVacancyInfo.LegalEntities.Single(l => l.LegalEntityId == legalEntityId); + var selectedOrganisation = employerVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile, vacancy, ukprn); var newLocation = locationEditModel.SelectedLocation == LocationViewModel.UseOtherLocationConst @@ -134,7 +137,6 @@ public async Task PostLocationEditModelAsync( { vacancy.LegalEntityName = selectedOrganisation.Name; vacancy.AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId; - vacancy.LegalEntityId = employerInfoModel.LegalEntityId.GetValueOrDefault(); vacancy.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption(); vacancy.AnonymousReason = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null; vacancy.EmployerName = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null; @@ -147,7 +149,7 @@ public async Task PostLocationEditModelAsync( { await _recruitVacancyClient.UpdateDraftVacancyAsync(vacancy, user); await UpdateEmployerProfileAsync(employerInfoModel, employerProfile, matchingAddress == null ? vacancy.EmployerLocation : null, user); - }); + }); } private Address GetMatchingAddress(string locationToMatch, IEnumerable
allLocations) @@ -160,7 +162,8 @@ private Address GetMatchingAddress(string locationToMatch, IEnumerable
private Address ConvertToDomainAddress(LocationEditModel locationEditModel) { - return new Address { + return new Address + { AddressLine1 = locationEditModel.AddressLine1, AddressLine2 = locationEditModel.AddressLine2, AddressLine3 = locationEditModel.AddressLine3, @@ -193,7 +196,7 @@ private async Task> GetAllAvailableLocationsAsync(EmployerProfile { var providerData = await _providerVacancyClient.GetProviderEditVacancyInfoAsync(ukprn); var employerInfo = providerData.Employers.Single(e => e.EmployerAccountId == vacancy.EmployerAccountId); - var legalEntity = employerInfo.LegalEntities.First(l => l.LegalEntityId == employerProfile.LegalEntityId); + var legalEntity = employerInfo.LegalEntities.First(l => l.AccountLegalEntityPublicHashedId == employerProfile.AccountLegalEntityPublicHashedId); var locations = new List
(); locations.Add(legalEntity.Address.ConvertToDomainAddress()); locations.AddRange(employerProfile.OtherLocations); diff --git a/src/Provider/Provider.Web/Orchestrators/VacancyPreviewOrchestrator.cs b/src/Provider/Provider.Web/Orchestrators/VacancyPreviewOrchestrator.cs index d418af2c79..3294042c7d 100644 --- a/src/Provider/Provider.Web/Orchestrators/VacancyPreviewOrchestrator.cs +++ b/src/Provider/Provider.Web/Orchestrators/VacancyPreviewOrchestrator.cs @@ -105,7 +105,7 @@ public async Task> SubmitVacancyAsyn private async Task SubmitActionAsync(Vacancy vacancy, VacancyUser user) { - var hasLegalEntityAgreementTask = _legalEntityAgreementService.HasLegalEntityAgreementAsync(vacancy.EmployerAccountId, vacancy.LegalEntityId); + var hasLegalEntityAgreementTask = _legalEntityAgreementService.HasLegalEntityAgreementAsync(vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId); var hasProviderAgreementTask = _trainingProviderAgreementService.HasAgreementAsync(vacancy.TrainingProvider.Ukprn.Value); await Task.WhenAll(hasLegalEntityAgreementTask, hasProviderAgreementTask); diff --git a/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityEditModel.cs b/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityEditModel.cs index d63581da0b..f83cb1c2d3 100644 --- a/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityEditModel.cs +++ b/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityEditModel.cs @@ -6,7 +6,7 @@ namespace Esfa.Recruit.Provider.Web.ViewModels.Part1.LegalEntity public class LegalEntityEditModel : VacancyRouteModel { [Required(ErrorMessage = ValidationMessages.EmployerSelectionValidationMessages.EmployerSelectionRequired)] - public long? SelectedOrganisationId { get; set; } + public string SelectedOrganisationId { get; set; } public string SearchTerm { get; set; } public int Page { get; set; } diff --git a/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityViewModel.cs b/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityViewModel.cs index 0f0a428cd1..05882c2ec0 100644 --- a/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityViewModel.cs +++ b/src/Provider/Provider.Web/ViewModels/Part1/LegalEntity/LegalEntityViewModel.cs @@ -22,7 +22,7 @@ public class LegalEntityViewModel nameof(SelectedOrganisationId) }; - public long? SelectedOrganisationId { get; internal set; } + public string SelectedOrganisationId { get; internal set; } public VacancyEmployerInfoModel VacancyEmployerInfoModel { get; internal set; } @@ -37,18 +37,18 @@ public class LegalEntityViewModel public int TotalNumberOfLegalEntities { get; internal set; } public bool IsPreviouslySelectedLegalEntityStillValid { get; internal set; } - public bool HasPreviouslyPersistedLegalEntity => SelectedOrganisationId.Value > 0; + public bool HasPreviouslyPersistedLegalEntity => !string.IsNullOrEmpty(SelectedOrganisationId); public bool IsSelectedOrganisationInPagedOrganisations => IsPreviouslySelectedLegalEntityStillValid && HasPreviouslyPersistedLegalEntity - && Organisations.Any(org => org.Id == SelectedOrganisationId.Value); + && Organisations.Any(org => org.Id == SelectedOrganisationId); - public bool CanOutputHiddenSelectedOrganisationIdField => SelectedOrganisationId.Value > 0 && IsSelectedOrganisationInPagedOrganisations == false; + public bool CanOutputHiddenSelectedOrganisationIdField => !string.IsNullOrEmpty(SelectedOrganisationId) && IsSelectedOrganisationInPagedOrganisations == false; } public class OrganisationViewModel { - public long Id { get; set; } + public string Id { get; set; } public string Name { get; set; } } } \ No newline at end of file diff --git a/src/Provider/UnitTests/Provider.Web/Orchestrators/Part1/LegalEntityOrchestratorTests.cs b/src/Provider/UnitTests/Provider.Web/Orchestrators/Part1/LegalEntityOrchestratorTests.cs index 4c9bfe4fba..a9f14c15bd 100644 --- a/src/Provider/UnitTests/Provider.Web/Orchestrators/Part1/LegalEntityOrchestratorTests.cs +++ b/src/Provider/UnitTests/Provider.Web/Orchestrators/Part1/LegalEntityOrchestratorTests.cs @@ -23,7 +23,7 @@ public class LegalEntityOrchestratorTests private readonly LegalEntityOrchestrator _orchestrator; private readonly Vacancy _testVacancy; private readonly VacancyRouteModel _testRouteModel = new VacancyRouteModel { Ukprn = TestUkprn, VacancyId = Guid.NewGuid() }; - + private readonly string AccountLegalEntityPublicHashedId = "ABCEFG"; public LegalEntityOrchestratorTests() { _mockLogger = new Mock>(); @@ -49,7 +49,7 @@ public async Task WhenNoLegalEntities_ShouldReturnEmptyList() _mockVacancyClient.Setup(x => x.GetVacancyAsync(It.IsAny())).ReturnsAsync(_testVacancy); - var result = await _orchestrator.GetLegalEntityViewModelAsync(_testRouteModel, TestUkprn, "", 1); + var result = await _orchestrator.GetLegalEntityViewModelAsync(_testRouteModel, TestUkprn, "", 1, AccountLegalEntityPublicHashedId); result.Organisations.Count().Should().Be(0); } diff --git a/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs b/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs index c06a70085f..f2dbf0e37d 100644 --- a/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs +++ b/src/Provider/UnitTests/Provider.Web/Orchestrators/VacancyPreviewOrchestratorTests.cs @@ -37,7 +37,7 @@ public async Task SubmitVacancyAsync_ShouldNotSubmitWhenMissingAgreements( const long ukprn = 12345678; const string employerAccountId = "ABCDEF"; const long legalEntityId = 1234; - + const string accountLegalEntityPublicHashedId = "XVYABD"; var fixture = new Fixture(); var vacancy = fixture.Create(); vacancy.Id = vacancyId; @@ -45,6 +45,7 @@ public async Task SubmitVacancyAsync_ShouldNotSubmitWhenMissingAgreements( vacancy.Status = VacancyStatus.Draft; vacancy.IsDeleted = false; vacancy.EmployerAccountId = employerAccountId; + vacancy.AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId; vacancy.LegalEntityId = legalEntityId; vacancy.OwnerType = OwnerType.Provider; @@ -69,7 +70,7 @@ public async Task SubmitVacancyAsync_ShouldNotSubmitWhenMissingAgreements( var review = new Mock(); var legalEntityAgreement = new Mock(); - legalEntityAgreement.Setup(l => l.HasLegalEntityAgreementAsync(employerAccountId, legalEntityId)) + legalEntityAgreement.Setup(l => l.HasLegalEntityAgreementAsync(employerAccountId, accountLegalEntityPublicHashedId)) .ReturnsAsync(hasLegalEntityAgreement); var agreementServiceMock = new Mock(); diff --git a/src/Shared/Recruit.Shared.Web/Services/ILegalEntityAgreementService.cs b/src/Shared/Recruit.Shared.Web/Services/ILegalEntityAgreementService.cs index bdbd3c46f5..bb2e9775d7 100644 --- a/src/Shared/Recruit.Shared.Web/Services/ILegalEntityAgreementService.cs +++ b/src/Shared/Recruit.Shared.Web/Services/ILegalEntityAgreementService.cs @@ -6,8 +6,8 @@ namespace Esfa.Recruit.Shared.Web.Services { public interface ILegalEntityAgreementService { - Task HasLegalEntityAgreementAsync(string employerAccountId, long legalEntityId); - Task GetLegalEntityAsync(string employerAccountId, long legalEntityId); + Task HasLegalEntityAgreementAsync(string employerAccountId, string accountLegalEntityPublicHashedId); + Task GetLegalEntityAsync(string employerAccountId, string accountLegalEntityPublicHashedId); Task HasLegalEntityAgreementAsync(string employerAccountId, LegalEntity legalEntity); } } \ No newline at end of file diff --git a/src/Shared/Recruit.Shared.Web/Services/LegalEntityAgreementService.cs b/src/Shared/Recruit.Shared.Web/Services/LegalEntityAgreementService.cs index 258f364b6c..60c71a9e96 100644 --- a/src/Shared/Recruit.Shared.Web/Services/LegalEntityAgreementService.cs +++ b/src/Shared/Recruit.Shared.Web/Services/LegalEntityAgreementService.cs @@ -14,9 +14,9 @@ public LegalEntityAgreementService(IEmployerVacancyClient client) _client = client; } - public async Task HasLegalEntityAgreementAsync(string employerAccountId, long legalEntityId) + public async Task HasLegalEntityAgreementAsync(string employerAccountId, string accountLegalEntityPublicHashedId) { - var legalEntity = await GetLegalEntityAsync(employerAccountId, legalEntityId); + var legalEntity = await GetLegalEntityAsync(employerAccountId, accountLegalEntityPublicHashedId); return await HasLegalEntityAgreementAsync(employerAccountId, legalEntity); } @@ -40,11 +40,11 @@ public async Task HasLegalEntityAgreementAsync(string employerAccountId, L return hasLegalEntityAgreement; } - public async Task GetLegalEntityAsync(string employerAccountId, long legalEntityId) + public async Task GetLegalEntityAsync(string employerAccountId, string accountLegalEntityPublicHashedId) { var employerData = await _client.GetEditVacancyInfoAsync(employerAccountId); - var legalEntity = employerData.LegalEntities.SingleOrDefault(l => l.LegalEntityId == legalEntityId); + var legalEntity = employerData.LegalEntities.SingleOrDefault(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); return legalEntity; } diff --git a/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/RefreshEmployerProfilesCommandHandler.cs b/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/RefreshEmployerProfilesCommandHandler.cs index 50b6f91467..6bf3220f02 100644 --- a/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/RefreshEmployerProfilesCommandHandler.cs +++ b/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/RefreshEmployerProfilesCommandHandler.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -7,6 +6,7 @@ using Esfa.Recruit.Vacancies.Client.Application.Providers; using Esfa.Recruit.Vacancies.Client.Domain.Entities; using Esfa.Recruit.Vacancies.Client.Domain.Repositories; +using Esfa.Recruit.Vacancies.Client.Infrastructure.Client; using MediatR; using Microsoft.Extensions.Logging; @@ -17,47 +17,50 @@ public class RefreshEmployerProfilesCommandHandler : IRequestHandler _logger; private readonly IEmployerProfileRepository _employerProfileRepository; private readonly ITimeProvider _time; + private readonly IEmployerVacancyClient _employerVacancyClient; public RefreshEmployerProfilesCommandHandler( ILogger logger, IEmployerProfileRepository employerProfileRepository, - ITimeProvider time) + ITimeProvider time, IEmployerVacancyClient employerVacancyClient) { _logger = logger; _employerProfileRepository = employerProfileRepository; _time = time; + _employerVacancyClient = employerVacancyClient; } public async Task Handle(RefreshEmployerProfilesCommand message, CancellationToken cancellationToken) { _logger.LogInformation("Refreshing Employer Profiles for {employerAccountId}", message.EmployerAccountId); - + var employerVacancyInfoTask = + _employerVacancyClient.GetEditVacancyInfoAsync(message.EmployerAccountId); var tasks = new List(); - + var editVacancyInfo = employerVacancyInfoTask.Result; // Get all current profiles for the employer var profiles = await _employerProfileRepository.GetEmployerProfilesForEmployerAsync(message.EmployerAccountId); - foreach (var legalEntity in message.LegalEntityIds) + foreach (var accountLegalEntityPublicHashedId in message.AccountLegalEntityPublicHashedIds) { - if (!profiles.Any(x => x.LegalEntityId == legalEntity)) - { + var selectedOrganisation = + editVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); + if (!profiles.Any(x => x.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId)) + { var currentTime = _time.Now; // Create new profile var newProfile = new EmployerProfile { EmployerAccountId = message.EmployerAccountId, - LegalEntityId = legalEntity, - CreatedDate = currentTime + CreatedDate = currentTime, + AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId }; - _logger.LogInformation("Adding new profile for employer account: {employerAccountId} and legal entity id: {legalEntityId}", message.EmployerAccountId, legalEntity); + _logger.LogInformation("Adding new profile for employer account: {employerAccountId} and Account LegalEntityPublicHashed id: {accountLegalEntityPublicHashedId}", message.EmployerAccountId, accountLegalEntityPublicHashedId); tasks.Add(_employerProfileRepository.CreateAsync(newProfile)); } } - await Task.WhenAll(tasks); - _logger.LogInformation($"Added {tasks.Count} new profile/s for {{employerAccountId}}", message.EmployerAccountId); } } diff --git a/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/UpdateEmployerProfileCommandHandler.cs b/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/UpdateEmployerProfileCommandHandler.cs index 06a095786e..fb6ffc1944 100644 --- a/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/UpdateEmployerProfileCommandHandler.cs +++ b/src/Shared/Recruit.Vacancies.Client/Application/CommandHandlers/UpdateEmployerProfileCommandHandler.cs @@ -28,10 +28,12 @@ public async Task Handle(UpdateEmployerProfileCommand message, CancellationToken { message.Profile.LastUpdatedDate = _time.Now; message.Profile.LastUpdatedBy = message.User; - + await _employerProfileRepository.UpdateAsync(message.Profile); - _logger.LogInformation("Update Employer profile for employer account: {employerAccountId} and legal entity: {legalEntityId} ", message.Profile.EmployerAccountId, message.Profile.LegalEntityId); + _logger.LogInformation("Update Employer profile for employer account: {employerAccountId} and " + + "AccountLegalEntityPublicHashedId:{AccountLegalEntityPublicHashedId}", message.Profile.EmployerAccountId, + message.Profile.AccountLegalEntityPublicHashedId); } } } \ No newline at end of file diff --git a/src/Shared/Recruit.Vacancies.Client/Application/Commands/RefreshEmployerProfilesCommand.cs b/src/Shared/Recruit.Vacancies.Client/Application/Commands/RefreshEmployerProfilesCommand.cs index 60e034ef67..f39e9a7195 100644 --- a/src/Shared/Recruit.Vacancies.Client/Application/Commands/RefreshEmployerProfilesCommand.cs +++ b/src/Shared/Recruit.Vacancies.Client/Application/Commands/RefreshEmployerProfilesCommand.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Esfa.Recruit.Vacancies.Client.Domain.Entities; using Esfa.Recruit.Vacancies.Client.Domain.Messaging; using MediatR; @@ -8,6 +7,6 @@ namespace Esfa.Recruit.Vacancies.Client.Application.Commands public class RefreshEmployerProfilesCommand : ICommand, IRequest { public string EmployerAccountId { get; set; } - public IEnumerable LegalEntityIds { get; set; } + public IEnumerable AccountLegalEntityPublicHashedIds { get; set; } } } diff --git a/src/Shared/Recruit.Vacancies.Client/Application/Services/EmployerService.cs b/src/Shared/Recruit.Vacancies.Client/Application/Services/EmployerService.cs index 35bc2e378b..956f5b8a0a 100644 --- a/src/Shared/Recruit.Vacancies.Client/Application/Services/EmployerService.cs +++ b/src/Shared/Recruit.Vacancies.Client/Application/Services/EmployerService.cs @@ -23,7 +23,7 @@ public async Task GetEmployerNameAsync(Vacancy vacancy) if (vacancy.EmployerNameOption == EmployerNameOption.TradingName) { - var profile = await _employerProfileRepository.GetAsync(vacancy.EmployerAccountId, vacancy.LegalEntityId); + var profile = await _employerProfileRepository.GetAsync(vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId); return profile.TradingName; } @@ -35,7 +35,7 @@ public async Task GetEmployerDescriptionAsync(Vacancy vacancy) if (!vacancy.CanEdit) return vacancy.EmployerDescription; - var profile = await _employerProfileRepository.GetAsync(vacancy.EmployerAccountId, vacancy.LegalEntityId); + var profile = await _employerProfileRepository.GetAsync(vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId); return profile?.AboutOrganisation ?? string.Empty; } } diff --git a/src/Shared/Recruit.Vacancies.Client/Domain/Entities/EmployerProfile.cs b/src/Shared/Recruit.Vacancies.Client/Domain/Entities/EmployerProfile.cs index 301bd8aefc..26d2bd2254 100644 --- a/src/Shared/Recruit.Vacancies.Client/Domain/Entities/EmployerProfile.cs +++ b/src/Shared/Recruit.Vacancies.Client/Domain/Entities/EmployerProfile.cs @@ -6,19 +6,20 @@ namespace Esfa.Recruit.Vacancies.Client.Domain.Entities public class EmployerProfile { private const string IdFormat = "{0}_{1}"; - public string Id => GetId(EmployerAccountId, LegalEntityId); + public string Id => GetId(EmployerAccountId, AccountLegalEntityPublicHashedId); public string EmployerAccountId { get; set; } - public long LegalEntityId { get; set; } public string AboutOrganisation { get; set; } public string OrganistationWebsiteUrl { get; set; } public string TradingName { get; set; } public DateTime CreatedDate { get; set; } public DateTime? LastUpdatedDate { get; set; } public VacancyUser LastUpdatedBy { get; set; } - public static string GetId(string employerAccountId, long legalEntityId) + public string AccountLegalEntityPublicHashedId { get; set; } + public static string GetId(string employerAccountId, string accountLegalEntityPublicHashedId) { - return string.Format(IdFormat, employerAccountId, legalEntityId); + return string.Format(IdFormat, employerAccountId, accountLegalEntityPublicHashedId); } public IList
OtherLocations { get; set; } = new List
(); + } } diff --git a/src/Shared/Recruit.Vacancies.Client/Domain/Repositories/IEmployerProfileRepository.cs b/src/Shared/Recruit.Vacancies.Client/Domain/Repositories/IEmployerProfileRepository.cs index 029470dd8a..454252dee0 100644 --- a/src/Shared/Recruit.Vacancies.Client/Domain/Repositories/IEmployerProfileRepository.cs +++ b/src/Shared/Recruit.Vacancies.Client/Domain/Repositories/IEmployerProfileRepository.cs @@ -8,7 +8,7 @@ public interface IEmployerProfileRepository { Task CreateAsync(EmployerProfile profile); Task> GetEmployerProfilesForEmployerAsync(string employerAccountId); - Task GetAsync(string employerAccountId, long legalEntityId); + Task GetAsync(string employerAccountId, string accountLegalEntityPublicHashedId); Task UpdateAsync(EmployerProfile profile); } } \ No newline at end of file diff --git a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IEmployerVacancyClient.cs b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IEmployerVacancyClient.cs index 3c780daba7..72f1d2a5d0 100644 --- a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IEmployerVacancyClient.cs +++ b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IEmployerVacancyClient.cs @@ -4,7 +4,6 @@ using Esfa.Recruit.Vacancies.Client.Domain.Entities; using Esfa.Recruit.Vacancies.Client.Infrastructure.QueryStore.Projections.Employer; using Esfa.Recruit.Vacancies.Client.Infrastructure.QueryStore.Projections.EditVacancyInfo; -using Esfa.Recruit.Vacancies.Client.Infrastructure.Services.TrainingProvider; using Esfa.Recruit.Vacancies.Client.Application.Validation; namespace Esfa.Recruit.Vacancies.Client.Infrastructure.Client diff --git a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IJobsVacancyClient.cs b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IJobsVacancyClient.cs index 4e12827a6f..d7999bfb44 100644 --- a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IJobsVacancyClient.cs +++ b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IJobsVacancyClient.cs @@ -20,7 +20,7 @@ public interface IJobsVacancyClient Task PerformRulesCheckAsync(Guid reviewId); Task WithdrawApplicationAsync(long vacancyReference, Guid candidateId); Task HardDeleteApplicationReviewsForCandidate(Guid candidateId); - Task RefreshEmployerProfiles(string employerAccountId, IEnumerable legalEntities); + Task RefreshEmployerProfiles(string employerAccountId, IEnumerable accountLegalEntityPublicHashedIds); Task UpdateUserAccountAsync(string idamsUserId); } } \ No newline at end of file diff --git a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IRecruitVacancyClient.cs b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IRecruitVacancyClient.cs index 7b154a9763..ba850c410a 100644 --- a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IRecruitVacancyClient.cs +++ b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/IRecruitVacancyClient.cs @@ -27,7 +27,7 @@ public interface IRecruitVacancyClient Task CloneVacancyAsync(Guid vacancyId, VacancyUser user, SourceOrigin sourceOrigin, DateTime startDate, DateTime closingDate); Task GetEmployerNameAsync(Vacancy vacancy); Task GetEmployerDescriptionAsync(Vacancy vacancy); - Task GetEmployerProfileAsync(string employerAccountId, long legalEntityId); + Task GetEmployerProfileAsync(string employerAccountId, string accountLegalEntityPublicHashedId); Task UpdateEmployerProfileAsync(EmployerProfile employerProfile, VacancyUser user); Task GetVacancyAnalyticsSummaryAsync(long vacancyReference); Task GetUsersDetailsAsync(string userId); diff --git a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/VacancyClient.cs b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/VacancyClient.cs index 1ff780c466..c4e3982e22 100644 --- a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/VacancyClient.cs +++ b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Client/VacancyClient.cs @@ -286,9 +286,9 @@ public Task SetApplicationReviewUnsuccessful(Guid applicationReviewId, string ca return _messaging.SendCommandAsync(command); } - public Task GetEmployerProfileAsync(string employerAccountId, long legalEntityId) + public Task GetEmployerProfileAsync(string employerAccountId, string accountLegalEntityPublicHashedId) { - return _employerProfileRepository.GetAsync(employerAccountId, legalEntityId); + return _employerProfileRepository.GetAsync(employerAccountId, accountLegalEntityPublicHashedId); } public Task UpdateEmployerProfileAsync(EmployerProfile employerProfile, VacancyUser user) @@ -422,12 +422,12 @@ public Task GetCurrentReferredVacancyReviewAsync(long vacancyRefe return _vacancyReviewQuery.GetCurrentReferredVacancyReviewAsync(vacancyReference); } - public Task RefreshEmployerProfiles(string employerAccountId, IEnumerable legalEntityIds) + public Task RefreshEmployerProfiles(string employerAccountId, IEnumerable accountLegalEntityPublicHashedIds) { return _messaging.SendCommandAsync(new RefreshEmployerProfilesCommand { EmployerAccountId = employerAccountId, - LegalEntityIds = legalEntityIds + AccountLegalEntityPublicHashedIds = accountLegalEntityPublicHashedIds }); } public Task GetUsersDetailsAsync(string userId) diff --git a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Repositories/MongoDbEmployerProfileRepository.cs b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Repositories/MongoDbEmployerProfileRepository.cs index 9d908259c2..de4483c9bc 100644 --- a/src/Shared/Recruit.Vacancies.Client/Infrastructure/Repositories/MongoDbEmployerProfileRepository.cs +++ b/src/Shared/Recruit.Vacancies.Client/Infrastructure/Repositories/MongoDbEmployerProfileRepository.cs @@ -25,10 +25,10 @@ await RetryPolicy.ExecuteAsync(_ => new Context(nameof(CreateAsync))); } - public async Task GetAsync(string employerAccountId, long legalEntityId) + public async Task GetAsync(string employerAccountId, string accountLegalEntityPublicHashedId) { var builder = Builders.Filter; - var filter = builder.Eq(x => x.Id, EmployerProfile.GetId(employerAccountId, legalEntityId)); + var filter = builder.Eq(x => x.Id, EmployerProfile.GetId(employerAccountId, accountLegalEntityPublicHashedId)); var collection = GetCollection(); @@ -56,7 +56,7 @@ public Task UpdateAsync(EmployerProfile profile) { var builder = Builders.Filter; var filter = builder.Eq(x => x.EmployerAccountId, profile.EmployerAccountId) & - builder.Eq(x => x.LegalEntityId, profile.LegalEntityId); + builder.Eq(x => x.AccountLegalEntityPublicHashedId, profile.AccountLegalEntityPublicHashedId); var collection = GetCollection(); diff --git a/src/Shared/UnitTests/Shared.Web/Services/LegalEntityAgreementServiceTests.cs b/src/Shared/UnitTests/Shared.Web/Services/LegalEntityAgreementServiceTests.cs index a31cc7d88d..df5dade0f9 100644 --- a/src/Shared/UnitTests/Shared.Web/Services/LegalEntityAgreementServiceTests.cs +++ b/src/Shared/UnitTests/Shared.Web/Services/LegalEntityAgreementServiceTests.cs @@ -13,16 +13,16 @@ namespace Esfa.Recruit.Vacancies.Client.UnitTests.Shared.Web.Services public class LegalEntityAgreementServiceTests { const string EmployerAccountId = "ABCDEF"; + const string AccountLegalEntityPublicHashedId = "XYZPQR"; const long LegalEntityId = 1234; - private Mock _clientMock; [Fact] public async Task HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLegalEntity() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, 5678, true, 5678, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, 5678, true, 5678, true, "5678"); - var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId); + var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId); result.Should().BeFalse(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Never); @@ -31,9 +31,9 @@ public async Task HasLegalEntityAgreementAsync_ShouldReturnFalseIfNoMatchingLega [Fact] public async Task HasLegalEntityAgreementAsync_ShouldNotCheckEmployerServiceWhenHasAgreement() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, true, LegalEntityId, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, true, LegalEntityId, true, AccountLegalEntityPublicHashedId); - var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId); + var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId); result.Should().BeTrue(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Never); @@ -42,9 +42,9 @@ public async Task HasLegalEntityAgreementAsync_ShouldNotCheckEmployerServiceWhen [Fact] public async Task HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHasNoAgreement() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, true, AccountLegalEntityPublicHashedId); - var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId); + var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId); result.Should().BeTrue(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); @@ -54,9 +54,9 @@ public async Task HasLegalEntityAgreementAsync_ShouldCheckEmployerServiceWhenHas [Fact] public async Task HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceLegalEntityHasNoAgreement() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, false); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, LegalEntityId, false, AccountLegalEntityPublicHashedId); - var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId); + var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId); result.Should().BeFalse(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); @@ -66,16 +66,16 @@ public async Task HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServ [Fact] public async Task HasLegalEntityAgreementAsync_ShouldReturnFalseWhenEmployerServiceCantLocateLegalEntity() { - var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, 5678, true); + var sut = GetLegalEntityAgreementService(EmployerAccountId, LegalEntityId, false, 5678, true, AccountLegalEntityPublicHashedId); - var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, LegalEntityId); + var result = await sut.HasLegalEntityAgreementAsync(EmployerAccountId, AccountLegalEntityPublicHashedId); result.Should().BeFalse(); _clientMock.Verify(c => c.GetEmployerLegalEntitiesAsync(EmployerAccountId), Times.Once); _clientMock.Verify(c => c.SetupEmployerAsync(EmployerAccountId), Times.Never); } - private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId, long legalEntityId, bool hasLegalEntityAgreement, long employerServiceLegalEntityId, bool employerServiceHasLegalEntityAgreement) + private LegalEntityAgreementService GetLegalEntityAgreementService(string employerAccountId, long legalEntityId, bool hasLegalEntityAgreement, long employerServiceLegalEntityId, bool employerServiceHasLegalEntityAgreement, string accountLegalEntityPublicHashedId) { _clientMock = new Mock(); _clientMock.Setup(c => c.GetEditVacancyInfoAsync(employerAccountId)).Returns(Task.FromResult( @@ -83,7 +83,12 @@ private LegalEntityAgreementService GetLegalEntityAgreementService(string employ { LegalEntities = new List { - new LegalEntity{LegalEntityId = legalEntityId, HasLegalEntityAgreement = hasLegalEntityAgreement} + new LegalEntity + { + LegalEntityId = legalEntityId, + AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId, + HasLegalEntityAgreement = hasLegalEntityAgreement + } } })); @@ -92,8 +97,9 @@ private LegalEntityAgreementService GetLegalEntityAgreementService(string employ { new LegalEntity { - LegalEntityId = employerServiceLegalEntityId, - HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement + LegalEntityId = employerServiceLegalEntityId, + AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId, + HasLegalEntityAgreement = employerServiceHasLegalEntityAgreement } } .AsEnumerable())); diff --git a/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerDescriptionTests.cs b/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerDescriptionTests.cs index 768d93338d..308e488a4a 100644 --- a/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerDescriptionTests.cs +++ b/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerDescriptionTests.cs @@ -5,7 +5,7 @@ using Moq; using Xunit; -namespace Esfa.Recruit.UnitTests.Vacancies.Client.Application.Services.EmployerService +namespace Esfa.Recruit.Vacancies.Client.UnitTests.Vacancies.Client.Application.Services.EmployerService { public class GetEmployerDescriptionTests { @@ -27,7 +27,7 @@ public async Task GetEmployerDescriptionAsync_ShouldReturnEmployerProfileAboutOr AboutOrganisation = employerProfileAboutOrganisation }; - _mockEmployerProfileRepository.Setup(pr => pr.GetAsync(It.IsAny(), It.IsAny())).ReturnsAsync(profile); + _mockEmployerProfileRepository.Setup(pr => pr.GetAsync(It.IsAny(), It.IsAny())).ReturnsAsync(profile); var sut = GetSut(); diff --git a/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerNameTests.cs b/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerNameTests.cs index 525813a326..850ca83fc4 100644 --- a/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerNameTests.cs +++ b/src/Shared/UnitTests/Vacancies.Client/Application/Services/EmployerService/GetEmployerNameTests.cs @@ -75,7 +75,7 @@ public async Task GetEmployerNameAsync_ShouldReturnTradingName(VacancyStatus sta TradingName = tradingName }; - _mockEmployerProfileRepository.Setup(pr => pr.GetAsync(It.IsAny(), It.IsAny())).ReturnsAsync(profile); + _mockEmployerProfileRepository.Setup(pr => pr.GetAsync(It.IsAny(), It.IsAny())).ReturnsAsync(profile); var sut = GetSut();