Skip to content

Commit

Permalink
Merge branch 'master' into CON-954-house-keeping-communications
Browse files Browse the repository at this point in the history
  • Loading branch information
VasanthaKasirajan3008 committed Sep 2, 2020
2 parents df9ee64 + 6d6a591 commit cd45ddf
Show file tree
Hide file tree
Showing 76 changed files with 292 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public LegalEntityAgreementController(
public async Task<IActionResult> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public async Task<IActionResult> 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)
Expand All @@ -60,16 +60,16 @@ public async Task<IActionResult> 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;
Expand Down
3 changes: 1 addition & 2 deletions src/Employer/Employer.Web/Models/VacancyEmployerInfoModel.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using Esfa.Recruit.Employer.Web.ViewModels.Part1.EmployerName;
using Esfa.Recruit.Shared.Web.Models;

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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public LegalEntityAgreementOrchestrator(
}

public async Task<LegalEntityAgreementSoftStopViewModel> 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(
Expand All @@ -56,7 +56,7 @@ public async Task<LegalEntityAgreementHardStopViewModel> GetLegalEntityAgreement
return new LegalEntityAgreementHardStopViewModel
{
HasLegalEntityAgreement = await _legalEntityAgreementService.HasLegalEntityAgreementAsync(
vacancy.EmployerAccountId, vacancy.LegalEntityId)
vacancy.EmployerAccountId, vacancy.AccountLegalEntityPublicHashedId)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public async Task<EmployerNameViewModel> 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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public EmployerOrchestrator(
_logger = logger;
}

public async Task<EmployerViewModel> GetEmployerViewModelAsync(VacancyRouteModel vrm, string searchTerm, int? requestedPageNo, long? selectedLegalEntityId = 0)
public async Task<EmployerViewModel> GetEmployerViewModelAsync(VacancyRouteModel vrm, string searchTerm, int? requestedPageNo, string selectedAccountLegalEntityPublicHashedId)
{
const int NotFoundIndex = -1;
var setPage = requestedPageNo.HasValue ? requestedPageNo.Value : 1;
Expand All @@ -49,17 +49,17 @@ public async Task<EmployerViewModel> 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))
Expand All @@ -69,8 +69,8 @@ public async Task<EmployerViewModel> 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);
Expand All @@ -82,12 +82,12 @@ public async Task<EmployerViewModel> 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)
Expand Down Expand Up @@ -148,7 +148,7 @@ private IEnumerable<OrganisationViewModel> 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};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<VacancyEmployerInfoModel> GetVacancyEmployerInfoModelAsync(Vac

var model = new VacancyEmployerInfoModel() {
VacancyId = vacancy.Id,
LegalEntityId = vacancy.LegalEntityId == 0 ? (long?) null : vacancy.LegalEntityId
AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId
};

if (vacancy.EmployerNameOption.HasValue)
Expand All @@ -63,7 +63,9 @@ public async Task<LocationViewModel> 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);
Expand All @@ -73,7 +75,7 @@ public async Task<LocationViewModel> 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);

Expand Down Expand Up @@ -119,12 +121,15 @@ public async Task<OrchestratorResponse> 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);

Expand All @@ -142,7 +147,6 @@ public async Task<OrchestratorResponse> 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;
Expand Down Expand Up @@ -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;
Expand All @@ -202,7 +211,7 @@ private async Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoMo
private async Task<List<Address>> 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<Address>();
locations.Add(legalEntity.Address.ConvertToDomainAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ public async Task<OrchestratorResponse> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private async Task<SubmitVacancyResponse> 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
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
}
Expand Down
Loading

0 comments on commit cd45ddf

Please sign in to comment.