public async Task <OrchestratorResponse> PostEmployerNameEditModelAsync( EmployerNameEditModel model, VacancyEmployerInfoModel employerInfoModel, VacancyUser user) { var validationRules = VacancyRuleSet.EmployerNameOption; var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _employerVacancyClient, _recruitVacancyClient, model, RouteNames.EmployerName_Post); vacancy.EmployerNameOption = model.SelectedEmployerIdentityOption.HasValue ? model.SelectedEmployerIdentityOption.Value.ConvertToDomainOption() : (EmployerNameOption?)null; // temporarily set the employer name for validation if (model.SelectedEmployerIdentityOption == EmployerIdentityOption.NewTradingName) { validationRules = VacancyRuleSet.EmployerNameOption | VacancyRuleSet.TradingName; vacancy.EmployerName = model.NewTradingName; _vmPropertyToMapEmployerNameTo = vm => vm.NewTradingName; } if (model.SelectedEmployerIdentityOption == EmployerIdentityOption.Anonymous) { vacancy.EmployerName = model.AnonymousName; vacancy.AnonymousReason = model.AnonymousReason; _vmPropertyToMapEmployerNameTo = vm => vm.AnonymousName; } return(await ValidateAndExecute( vacancy, v => _recruitVacancyClient.Validate(v, validationRules), v => Task.FromResult(new OrchestratorResponse(true)))); }
private async Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoModel, 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; employerProfile.TradingName = employerInfoModel.NewTradingName; } if (address != null) { updateProfile = true; employerProfile.OtherLocations.Add(address); } if (updateProfile) { await _recruitVacancyClient.UpdateEmployerProfileAsync(employerProfile, user); } }
public async Task PostLocationEditModelAsync(LocationEditModel model, VacancyEmployerInfoModel vacancyEmployerInfoModel = null) { await Sut.PostLocationEditModelAsync(model, User, Vacancy.TrainingProvider.Ukprn.Value, vacancyEmployerInfoModel ?? new VacancyEmployerInfoModel { VacancyId = Vacancy.Id }); }
public async Task <OrchestratorResponse> PostLocationEditModelAsync( LocationEditModel locationEditModel, VacancyEmployerInfoModel employerInfoModel, VacancyUser user) { if (string.IsNullOrEmpty(locationEditModel.SelectedLocation)) { return(new OrchestratorResponse(false)); } var vacancyTask = Utility.GetAuthorisedVacancyForEditAsync( _employerVacancyClient, _recruitVacancyClient, locationEditModel, RouteNames.Employer_Post); var employerVacancyInfoTask = _employerVacancyClient.GetEditVacancyInfoAsync(locationEditModel.EmployerAccountId); await Task.WhenAll(vacancyTask, employerVacancyInfoTask); var vacancy = vacancyTask.Result; var editVacancyInfo = employerVacancyInfoTask.Result; var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId) ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId; var selectedOrganisation = editVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var employerProfile = await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, selectedOrganisation.AccountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile); var newLocation = locationEditModel.SelectedLocation == LocationViewModel.UseOtherLocationConst ? locationEditModel.ToAddressString() : locationEditModel.SelectedLocation; var matchingAddress = GetMatchingAddress(newLocation, allLocations); vacancy.EmployerLocation = matchingAddress != null ? matchingAddress : ConvertToDomainAddress(locationEditModel); //if cookie is found then update legal entity and name option from cookie if (employerInfoModel != null) { vacancy.LegalEntityName = selectedOrganisation.Name; vacancy.AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId; vacancy.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption(); vacancy.AnonymousReason = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null; vacancy.EmployerName = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null; } return(await ValidateAndExecute( vacancy, v => _recruitVacancyClient.Validate(v, ValidationRules), async v => { await _recruitVacancyClient.UpdateDraftVacancyAsync(vacancy, user); await UpdateEmployerProfile(employerInfoModel, employerProfile, matchingAddress == null ? vacancy.EmployerLocation : null, user); })); }
public async Task PostLocationEditModelAsync(LocationEditModel model, VacancyEmployerInfoModel vacancyEmployerInfoModel = null) { await Sut.PostLocationEditModelAsync(model, vacancyEmployerInfoModel ?? new VacancyEmployerInfoModel { VacancyId = Vacancy.Id }, User); }
public async Task <LocationViewModel> GetLocationViewModelAsync( VacancyRouteModel vrm, VacancyEmployerInfoModel employerInfoModel, VacancyUser user) { var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_employerVacancyClient, _recruitVacancyClient, vrm, RouteNames.Location_Get); var accountLegalEntityPublicHashedId = employerInfoModel?.AccountLegalEntityPublicHashedId != null ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId; var vm = new LocationViewModel(); vm.PageInfo = Utility.GetPartOnePageInfo(vacancy); vm.IsAnonymousVacancy = (employerInfoModel?.EmployerIdentityOption == null) ? vacancy.IsAnonymous : employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.Anonymous; var employerProfile = await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile); vm.AvailableLocations = allLocations.Select(a => a.ToAddressString()).ToList(); var hasLegalEntityChanged = employerInfoModel?.HasLegalEntityChanged ?? false; if (vacancy.EmployerLocation != null && hasLegalEntityChanged == false) { var matchingAddress = GetMatchingAddress(vacancy.EmployerLocation.ToAddressString(), allLocations); if (matchingAddress == null) { vm.SelectedLocation = LocationViewModel.UseOtherLocationConst; vm.SetLocation(vacancy.EmployerLocation); } else { vm.SelectedLocation = matchingAddress.ToAddressString(); } } if (vacancy.Status == VacancyStatus.Referred) { vm.Review = await _reviewSummaryService.GetReviewSummaryViewModelAsync(vacancy.VacancyReference.Value, ReviewFieldMappingLookups.GetLocationFieldIndicators()); } return(vm); }
public async Task <IActionResult> EmployerName(EmployerNameEditModel model, [FromQuery] bool wizard) { var employerInfoModel = GetVacancyEmployerInfoCookie(model.VacancyId); //respective cookie can go missing if user has opened another vacancy in a different browser tab if (employerInfoModel == null && !_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList)) { return(RedirectToRoute(RouteNames.Employer_Get)); } if (_feature.IsFeatureEnabled(FeatureNames.EmployerTaskList)) { employerInfoModel = new VacancyEmployerInfoModel { VacancyId = model.VacancyId }; } var response = await _orchestrator.PostEmployerNameEditModelAsync(model, User.ToVacancyUser()); if (!response.Success) { response.AddErrorsToModelState(ModelState); } if (!ModelState.IsValid) { var vm = await _orchestrator.GetEmployerNameViewModelAsync(model, employerInfoModel); vm.PageInfo.SetWizard(wizard); vm.NewTradingName = model.NewTradingName; vm.SelectedEmployerIdentityOption = model.SelectedEmployerIdentityOption; vm.AnonymousName = model.AnonymousName; vm.AnonymousReason = model.AnonymousReason; return(View(vm)); } employerInfoModel.EmployerIdentityOption = model.SelectedEmployerIdentityOption; employerInfoModel.NewTradingName = model.SelectedEmployerIdentityOption == EmployerIdentityOption.NewTradingName ? model.NewTradingName : null; employerInfoModel.AnonymousName = model.SelectedEmployerIdentityOption == EmployerIdentityOption.Anonymous ? model.AnonymousName : null; employerInfoModel.AnonymousReason = model.SelectedEmployerIdentityOption == EmployerIdentityOption.Anonymous ? model.AnonymousReason : null; SetVacancyEmployerInfoCookie(employerInfoModel); return(RedirectToRoute(RouteNames.LegalEntityAgreement_SoftStop_Get, new { Wizard = wizard })); }
public async Task <VacancyEmployerInfoModel> GetVacancyEmployerInfoModelAsync(VacancyRouteModel vrm) { var vacancy = await _utility.GetAuthorisedVacancyForEditAsync(vrm, RouteNames.Employer_Post); var model = new VacancyEmployerInfoModel() { VacancyId = vacancy.Id, AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId }; if (vacancy.EmployerNameOption.HasValue) { model.EmployerIdentityOption = vacancy.EmployerNameOption.Value.ConvertToModelOption(); model.AnonymousName = vacancy.IsAnonymous ? vacancy.EmployerName : null; model.AnonymousReason = vacancy.IsAnonymous ? vacancy.AnonymousReason : null; } return(model); }
public async Task <VacancyEmployerInfoModel> GetVacancyEmployerInfoModelAsync(VacancyRouteModel vrm) { var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _providerVacancyClient, _recruitVacancyClient, vrm, RouteNames.Location_Get); var model = new VacancyEmployerInfoModel() { VacancyId = vacancy.Id, LegalEntityId = vacancy.LegalEntityId == 0 ? (long?)null : vacancy.LegalEntityId }; if (vacancy.EmployerNameOption.HasValue) { model.EmployerIdentityOption = vacancy.EmployerNameOption.Value.ConvertToModelOption(); model.AnonymousName = vacancy.IsAnonymous ? vacancy.EmployerName : null; model.AnonymousReason = vacancy.IsAnonymous ? vacancy.AnonymousReason : null; } return(model); }
private async Task UpdateEmployerProfileAsync(VacancyEmployerInfoModel employerInfoModel, EmployerProfile employerProfile, Address address, VacancyUser user) { var updateProfile = false; if (employerInfoModel != null && employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.NewTradingName) { updateProfile = true; employerProfile.TradingName = employerInfoModel.NewTradingName; } if (address != null) { updateProfile = true; employerProfile.OtherLocations.Add(address); } if (updateProfile) { await _recruitVacancyClient.UpdateEmployerProfileAsync(employerProfile, user); } }
public async Task Then_The_Vacancy_Is_Updated_With_The_AccountLegalEntityPublicHashedId( VacancyRouteModel vacancyRouteModel, VacancyEmployerInfoModel vacancyEmployerInfoModel, VacancyUser vacancyUser, Vacancy vacancy, [Frozen] Mock <IUtility> utility, [Frozen] Mock <IRecruitVacancyClient> vacancyClient, EmployerOrchestrator orchestrator) { utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(vacancyRouteModel, RouteNames.Employer_Get)) .ReturnsAsync(vacancy); vacancyClient.Setup(x => x.Validate(vacancy, VacancyRuleSet.None)) .Returns(new EntityValidationResult { Errors = null }); await orchestrator.SetAccountLegalEntityPublicId(vacancyRouteModel, vacancyEmployerInfoModel, vacancyUser); vacancyClient.Verify(x => x.UpdateDraftVacancyAsync(It.Is <Vacancy>(c => c.AccountLegalEntityPublicHashedId.Equals(vacancyEmployerInfoModel.AccountLegalEntityPublicHashedId)), vacancyUser), Times.Once); }
public async Task <EmployerNameViewModel> GetEmployerNameViewModelAsync( VacancyRouteModel vrm, VacancyEmployerInfoModel employerInfoModel, VacancyUser user) { var vacancy = await Utility.GetAuthorisedVacancyForEditAsync( _providerVacancyClient, _recruitVacancyClient, vrm, RouteNames.EmployerName_Get); var accountLegalEntityPublicHashedId = employerInfoModel.AccountLegalEntityPublicHashedId; var getVacancyEditInfoTask = _providerVacancyClient.GetProviderEditVacancyInfoAsync(vrm.Ukprn); 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.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var vm = new EmployerNameViewModel { HasOnlyOneOrganisation = employerInfo.LegalEntities.Count() == 1, LegalEntityName = legalEntity.Name, ExistingTradingName = employerProfile?.TradingName, PageInfo = Utility.GetPartOnePageInfo(vacancy), SelectedEmployerIdentityOption = employerInfoModel.EmployerIdentityOption, NewTradingName = employerInfoModel.NewTradingName, AnonymousName = employerInfoModel.AnonymousName, AnonymousReason = employerInfoModel.AnonymousReason }; if (vacancy.Status == VacancyStatus.Referred) { vm.Review = await _reviewSummaryService.GetReviewSummaryViewModelAsync(vacancy.VacancyReference.Value, ReviewFieldMappingLookups.GetEmployerNameReviewFieldIndicators()); } return(vm); }
public async Task <EmployerNameViewModel> GetEmployerNameViewModelAsync(VacancyRouteModel vrm, VacancyEmployerInfoModel employerInfoModel) { var vacancy = await _utility.GetAuthorisedVacancyForEditAsync(vrm, RouteNames.Employer_Get); var accountLegalEntityPublicHashedId = employerInfoModel?.AccountLegalEntityPublicHashedId ?? vacancy.AccountLegalEntityPublicHashedId; if (string.IsNullOrEmpty(accountLegalEntityPublicHashedId)) { return(null); } var getEmployerDataTask = _employerVacancyClient.GetEditVacancyInfoAsync(vrm.EmployerAccountId); 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.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var vm = new EmployerNameViewModel { HasOnlyOneOrganisation = editVacancyInfo.LegalEntities.Count() == 1, LegalEntityName = legalEntity.Name, ExistingTradingName = employerProfile.TradingName, PageInfo = _utility.GetPartOnePageInfo(vacancy), SelectedEmployerIdentityOption = employerInfoModel?.EmployerIdentityOption ?? vacancy?.EmployerNameOption?.ConvertToModelOption(), NewTradingName = employerInfoModel?.NewTradingName, AnonymousName = employerInfoModel?.AnonymousName, AnonymousReason = employerInfoModel?.AnonymousReason ?? vacancy?.AnonymousReason, TaskListCompleted = _utility.TaskListCompleted(vacancy) }; if (vacancy.Status == VacancyStatus.Referred) { vm.Review = await _reviewSummaryService.GetReviewSummaryViewModelAsync(vacancy.VacancyReference.Value, ReviewFieldMappingLookups.GetEmployerNameReviewFieldIndicators()); } return(vm); }
protected void SetVacancyEmployerInfoCookie(VacancyEmployerInfoModel model) { var info = JsonConvert.SerializeObject(model); Response.Cookies.SetSessionCookie(_hostingEnvironment, CookieNames.VacancyEmployerInfo, info); }
public async Task <OrchestratorResponse> PostLocationEditModelAsync( LocationEditModel locationEditModel, VacancyEmployerInfoModel employerInfoModel, VacancyUser user) { if (string.IsNullOrEmpty(locationEditModel.SelectedLocation)) { return(new OrchestratorResponse(false)); } var vacancyTask = _utility.GetAuthorisedVacancyForEditAsync(locationEditModel, RouteNames.Employer_Post); var employerVacancyInfoTask = _employerVacancyClient.GetEditVacancyInfoAsync(locationEditModel.EmployerAccountId); await Task.WhenAll(vacancyTask, employerVacancyInfoTask); var vacancy = vacancyTask.Result; var editVacancyInfo = employerVacancyInfoTask.Result; var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId) ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId; var selectedOrganisation = editVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId); var employerProfile = await _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, selectedOrganisation.AccountLegalEntityPublicHashedId); var allLocations = await GetAllAvailableLocationsAsync(employerProfile); var newLocation = locationEditModel.SelectedLocation == LocationViewModel.UseOtherLocationConst ? locationEditModel.ToAddressString() : locationEditModel.SelectedLocation; var matchingAddress = GetMatchingAddress(newLocation, allLocations); var employerLocation = matchingAddress != null ? matchingAddress : ConvertToDomainAddress(locationEditModel); // this has diverged from the usual pattern because the individual properties are review fields SetVacancyWithEmployerReviewFieldIndicators( vacancy.EmployerLocation?.AddressLine1, FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine1), vacancy, (v) => { return(employerLocation.AddressLine1); }); SetVacancyWithEmployerReviewFieldIndicators( vacancy.EmployerLocation?.AddressLine2, FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine2), vacancy, (v) => { return(employerLocation.AddressLine2); }); SetVacancyWithEmployerReviewFieldIndicators( vacancy.EmployerLocation?.AddressLine3, FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine3), vacancy, (v) => { return(employerLocation.AddressLine3); }); SetVacancyWithEmployerReviewFieldIndicators( vacancy.EmployerLocation?.AddressLine4, FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine4), vacancy, (v) => { return(employerLocation.AddressLine4); }); SetVacancyWithEmployerReviewFieldIndicators( vacancy.EmployerLocation?.Postcode, FieldIdResolver.ToFieldId(v => v.EmployerLocation.Postcode), vacancy, (v) => { return(employerLocation.Postcode); }); vacancy.EmployerLocation = employerLocation; // if cookie is found then update legal entity and name option from cookie if (employerInfoModel != null) { SetVacancyWithEmployerReviewFieldIndicators( vacancy.LegalEntityName, FieldIdResolver.ToFieldId(v => v.EmployerName), vacancy, (v) => { return(v.LegalEntityName = selectedOrganisation.Name); }); SetVacancyWithEmployerReviewFieldIndicators( vacancy.EmployerNameOption, FieldIdResolver.ToFieldId(v => v.EmployerName), vacancy, (v) => { return(v.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption()); }); if (employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.NewTradingName) { SetVacancyWithEmployerReviewFieldIndicators( employerProfile.TradingName, FieldIdResolver.ToFieldId(v => v.EmployerName), vacancy, (e) => { // the indicator will be set for the vacancy when the employer profile will change to the new trading name return(employerInfoModel.NewTradingName); }); } vacancy.AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId; vacancy.AnonymousReason = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null; vacancy.EmployerName = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null; } return(await ValidateAndExecute( vacancy, v => _recruitVacancyClient.Validate(v, ValidationRules), async v => { await _recruitVacancyClient.UpdateDraftVacancyAsync(vacancy, user); await UpdateEmployerProfile(employerInfoModel, employerProfile, matchingAddress == null ? vacancy.EmployerLocation : null, user); })); }