Skip to content

Commit

Permalink
Merge branch 'master' into CON-3845-Make-submission-pages-consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Howes committed Sep 3, 2021
2 parents e9ceca6 + 2aadc90 commit b537863
Show file tree
Hide file tree
Showing 57 changed files with 3,659 additions and 416 deletions.
19 changes: 15 additions & 4 deletions src/Employer/Employer.Web/Controllers/VacancyPreviewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public VacancyPreviewController(VacancyPreviewOrchestrator orchestrator)
}

[HttpGet("preview", Name = RouteNames.Vacancy_Preview_Get)]
public async Task<IActionResult> VacancyPreview(VacancyRouteModel vrm, string selection = null)
public async Task<IActionResult> VacancyPreview(VacancyRouteModel vrm, bool? submitToEfsa = null)
{
var viewModel = await _orchestrator.GetVacancyPreviewViewModelAsync(vrm);
AddSoftValidationErrorsToModelState(viewModel);
SetSectionStates(viewModel);

viewModel.CanHideValidationSummary = true;
ViewBag.Selection = selection;
viewModel.SubmitToEsfa = submitToEfsa;

if (TempData.ContainsKey(TempDataKeys.VacancyClonedInfoMessage))
viewModel.VacancyClonedInfoMessage = TempData[TempDataKeys.VacancyClonedInfoMessage].ToString();
Expand All @@ -50,13 +50,24 @@ public async Task<IActionResult> Review(SubmitReviewModel m)
{
if (ModelState.IsValid)
{
if(m.SubmitToEsfa.Value)
{
await _orchestrator.ClearRejectedVacancyReason(m, User.ToVacancyUser());
}
else
{
await _orchestrator.UpdateRejectedVacancyReason(m, User.ToVacancyUser());
}

return RedirectToRoute(m.SubmitToEsfa.GetValueOrDefault()
? RouteNames.ApproveJobAdvert_Get
: RouteNames.RejectJobAdvert_Get);
}

var viewModel = await _orchestrator.GetVacancyPreviewViewModelAsync(m);
viewModel.SoftValidationErrors = null;
viewModel.SubmitToEsfa = m.SubmitToEsfa;
viewModel.RejectedReason = m.RejectedReason;
SetSectionStates(viewModel);

return View(ViewNames.VacancyPreview, viewModel);
Expand Down Expand Up @@ -125,7 +136,7 @@ public async Task<IActionResult> ApproveJobAdvert(ApproveJobAdvertViewModel vm)
}
else
{
return RedirectToRoute(RouteNames.Vacancy_Preview_Get, new { VacancyId = vm.VacancyId, Selection = "Approve" });
return RedirectToRoute(RouteNames.Vacancy_Preview_Get, new { VacancyId = vm.VacancyId, SubmitToEfsa = true });
}

var viewModel = await _orchestrator.GetVacancyPreviewViewModelAsync(vm);
Expand Down Expand Up @@ -167,7 +178,7 @@ public async Task<IActionResult> RejectJobAdvert(RejectJobAdvertViewModel vm)
}
}

return RedirectToRoute(RouteNames.Vacancy_Preview_Get, new { VacancyId = vm.VacancyId, Selection = "Reject" });
return RedirectToRoute(RouteNames.Vacancy_Preview_Get, new { VacancyId = vm.VacancyId, SubmitToEfsa = false });
}

[HttpGet("confirmation-advert", Name = RouteNames.JobAdvertConfirmation_Get)]
Expand Down
35 changes: 29 additions & 6 deletions src/Employer/Employer.Web/Orchestrators/Part1/DatesOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Esfa.Recruit.Shared.Web.Orchestrators;
using Esfa.Recruit.Shared.Web.Services;
using Esfa.Recruit.Vacancies.Client.Application.Providers;
using Esfa.Recruit.Vacancies.Client.Application.Services;
using Esfa.Recruit.Vacancies.Client.Application.Validation;
using Esfa.Recruit.Vacancies.Client.Domain.Entities;
using Esfa.Recruit.Vacancies.Client.Domain.Extensions;
Expand All @@ -15,7 +16,7 @@

namespace Esfa.Recruit.Employer.Web.Orchestrators.Part1
{
public class DatesOrchestrator : EntityValidatingOrchestrator<Vacancy, DatesEditModel>
public class DatesOrchestrator : VacancyValidatingOrchestrator<DatesEditModel>
{
private const VacancyRuleSet ValidationRules = VacancyRuleSet.ClosingDate | VacancyRuleSet.StartDate | VacancyRuleSet.StartDateEndDate | VacancyRuleSet.TrainingExpiryDate;
private readonly IEmployerVacancyClient _client;
Expand Down Expand Up @@ -99,11 +100,33 @@ public async Task<OrchestratorResponse> PostDatesEditModelAsync(DatesEditModel m
{
var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_client, _vacancyClient, m, RouteNames.Dates_Post);

vacancy.ClosingDate = m.ClosingDate.AsDateTimeUk()?.ToUniversalTime();
vacancy.StartDate = m.StartDate.AsDateTimeUk()?.ToUniversalTime();

vacancy.DisabilityConfident = m.IsDisabilityConfident ? DisabilityConfident.Yes : DisabilityConfident.No;

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.ClosingDate,
FieldIdResolver.ToFieldId(v => v.ClosingDate),
vacancy,
(v) =>
{
return v.ClosingDate = m.ClosingDate.AsDateTimeUk()?.ToUniversalTime();
});

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.StartDate,
FieldIdResolver.ToFieldId(v => v.StartDate),
vacancy,
(v) =>
{
return v.StartDate = m.StartDate.AsDateTimeUk()?.ToUniversalTime();
});

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.DisabilityConfident,
FieldIdResolver.ToFieldId(v => v.DisabilityConfident),
vacancy,
(v) =>
{
return v.DisabilityConfident = m.IsDisabilityConfident ? DisabilityConfident.Yes : DisabilityConfident.No;
});

return await ValidateAndExecute(
vacancy,
v => _vacancyClient.Validate(v, ValidationRules),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
using Esfa.Recruit.Shared.Web.Extensions;
using Esfa.Recruit.Shared.Web.Orchestrators;
using Esfa.Recruit.Shared.Web.Services;
using Esfa.Recruit.Vacancies.Client.Application.Services;
using Esfa.Recruit.Vacancies.Client.Application.Validation;
using Esfa.Recruit.Vacancies.Client.Domain.Entities;
using Esfa.Recruit.Vacancies.Client.Infrastructure.Client;
using Microsoft.Extensions.Logging;

namespace Esfa.Recruit.Employer.Web.Orchestrators.Part1
{
public class DurationOrchestrator : EntityValidatingOrchestrator<Vacancy, DurationEditModel>
public class DurationOrchestrator : VacancyValidatingOrchestrator<DurationEditModel>
{
private const VacancyRuleSet ValidationRules = VacancyRuleSet.Duration | VacancyRuleSet.WorkingWeekDescription | VacancyRuleSet.WeeklyHours;
private readonly IEmployerVacancyClient _client;
Expand Down Expand Up @@ -72,11 +73,42 @@ public async Task<OrchestratorResponse> PostDurationEditModelAsync(DurationEditM
if(vacancy.Wage == null)
vacancy.Wage = new Wage();

vacancy.Wage.Duration = int.TryParse(m.Duration, out int duration) ? duration : default(int?);
vacancy.Wage.DurationUnit = m.DurationUnit;
vacancy.Wage.WorkingWeekDescription = m.WorkingWeekDescription;
vacancy.Wage.WeeklyHours = m.WeeklyHours.AsDecimal(2);

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.Wage.Duration,
FieldIdResolver.ToFieldId(v => v.Wage.Duration),
vacancy,
(v) =>
{
return v.Wage.Duration = int.TryParse(m.Duration, out int duration) ? duration : default(int?);
});

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.Wage.DurationUnit,
FieldIdResolver.ToFieldId(v => v.Wage.DurationUnit),
vacancy,
(v) =>
{
return v.Wage.DurationUnit = m.DurationUnit;
});

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.Wage.WorkingWeekDescription,
FieldIdResolver.ToFieldId(v => v.Wage.WorkingWeekDescription),
vacancy,
(v) =>
{
return v.Wage.WorkingWeekDescription = m.WorkingWeekDescription;
});

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.Wage.WeeklyHours,
FieldIdResolver.ToFieldId(v => v.Wage.WeeklyHours),
vacancy,
(v) =>
{
return v.Wage.WeeklyHours = m.WeeklyHours.AsDecimal(2);
});

return await ValidateAndExecute(
vacancy,
v => _vacancyClient.Validate(v, ValidationRules),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
using Esfa.Recruit.Shared.Web.Services;
using Esfa.Recruit.Employer.Web.Mappings;
using Esfa.Recruit.Shared.Web.Models;
using Esfa.Recruit.Vacancies.Client.Application.Services;

namespace Esfa.Recruit.Employer.Web.Orchestrators.Part1
{
public class LocationOrchestrator : EntityValidatingOrchestrator<Vacancy, LocationEditModel>
public class LocationOrchestrator : VacancyValidatingOrchestrator<LocationEditModel>
{
private const VacancyRuleSet ValidationRules = VacancyRuleSet.EmployerAddress;
private readonly IEmployerVacancyClient _employerVacancyClient;
Expand Down Expand Up @@ -140,14 +141,91 @@ public async Task<OrchestratorResponse> PostLocationEditModelAsync(

var matchingAddress = GetMatchingAddress(newLocation, allLocations);

vacancy.EmployerLocation = matchingAddress != null ? matchingAddress : ConvertToDomainAddress(locationEditModel);
var employerLocation = matchingAddress != null ? matchingAddress : ConvertToDomainAddress(locationEditModel);

//if cookie is found then update legal entity and name option from cookie
// 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)
{
vacancy.LegalEntityName = selectedOrganisation.Name;
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.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption();
vacancy.AnonymousReason = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null;
vacancy.EmployerName = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null;
}
Expand All @@ -161,6 +239,7 @@ public async Task<OrchestratorResponse> PostLocationEditModelAsync(
await UpdateEmployerProfile(employerInfoModel, employerProfile, matchingAddress == null ? vacancy.EmployerLocation : null, user);
});
}

private Address GetMatchingAddress(string locationToMatch, IEnumerable<Address> allLocations)
{
var matchingLocation =
Expand Down Expand Up @@ -206,8 +285,6 @@ private async Task UpdateEmployerProfile(VacancyEmployerInfoModel employerInfoMo
}
}



private async Task<List<Address>> GetAllAvailableLocationsAsync(EmployerProfile employerProfile)
{
var employerData = await _employerVacancyClient.GetEditVacancyInfoAsync(employerProfile.EmployerAccountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
using Esfa.Recruit.Employer.Web.ViewModels.Part1.NumberOfPositions;
using Esfa.Recruit.Shared.Web.Orchestrators;
using Esfa.Recruit.Shared.Web.Services;
using Esfa.Recruit.Vacancies.Client.Application.Services;
using Esfa.Recruit.Vacancies.Client.Application.Validation;
using Esfa.Recruit.Vacancies.Client.Domain.Entities;
using Esfa.Recruit.Vacancies.Client.Infrastructure.Client;
using Microsoft.Extensions.Logging;

namespace Esfa.Recruit.Employer.Web.Orchestrators.Part1
{
public class NumberOfPositionsOrchestrator : EntityValidatingOrchestrator<Vacancy, NumberOfPositionsEditModel>
public class NumberOfPositionsOrchestrator : VacancyValidatingOrchestrator<NumberOfPositionsEditModel>
{
private const VacancyRuleSet ValidationRules = VacancyRuleSet.NumberOfPositions;
private readonly IEmployerVacancyClient _client;
Expand Down Expand Up @@ -58,9 +59,17 @@ public async Task<NumberOfPositionsViewModel> GetNumberOfPositionsViewModelAsync

public async Task<OrchestratorResponse<Guid>> PostNumberOfPositionsEditModelAsync(NumberOfPositionsEditModel m, VacancyUser user)
{
var numberOfPositions = int.TryParse(m.NumberOfPositions, out var n)? n : default(int?);
var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_client, _vacancyClient,m, RouteNames.NumberOfPositions_Post);
vacancy.NumberOfPositions = numberOfPositions;

SetVacancyWithEmployerReviewFieldIndicators(
vacancy.NumberOfPositions,
FieldIdResolver.ToFieldId(v => v.NumberOfPositions),
vacancy,
(v) =>
{
return v.NumberOfPositions = int.TryParse(m.NumberOfPositions, out var n) ? n : default(int?);
});

return await ValidateAndExecute(
vacancy,
v => _vacancyClient.Validate(v, ValidationRules),
Expand Down
Loading

0 comments on commit b537863

Please sign in to comment.