public IActionResult LocationChoiceSelection(bool?national) { LocationChoiceSelectionViewModel model = new LocationChoiceSelectionViewModel(); if (national == null) { model.NationalApprenticeship = NationalApprenticeship.Undefined; } if (national.HasValue) { model.NationalApprenticeship = national.Value ? NationalApprenticeship.Yes : NationalApprenticeship.No; } return(View("../Apprenticeships/LocationChoiceSelection/Index", model)); }
public IActionResult LocationChoiceSelection(LocationChoiceSelectionViewModel model) { var apprenticeship = _session.GetObject <Apprenticeship>("selectedApprenticeship"); var location = apprenticeship.ApprenticeshipLocations.FirstOrDefault(x => x.ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased); switch (model.NationalApprenticeship) { case NationalApprenticeship.Yes: if (location == null) { apprenticeship.ApprenticeshipLocations.Add(CreateRegionLocation(new string[0], true)); } else { apprenticeship.ApprenticeshipLocations.RemoveAll(x => x.ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased); apprenticeship.ApprenticeshipLocations.Add(CreateRegionLocation(new string[0], true)); } _session.SetObject("selectedApprenticeship", apprenticeship); return(RedirectToAction("Summary", "Apprenticeships", new {})); case NationalApprenticeship.No: if (location != null) { apprenticeship.ApprenticeshipLocations.RemoveAll(x => x.ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased); apprenticeship.ApprenticeshipLocations.Add(CreateRegionLocation(new string[0], false)); } _session.SetObject("selectedApprenticeship", apprenticeship); return(RedirectToAction("Regions", "Apprenticeships", new {})); default: return(View("../ApprenticeShips/Search/Index")); } }