public MediatorResponse <ApprenticeshipSearchResponseViewModel> Results(ApprenticeshipSearchViewModel model) { UserDataProvider.Pop(CandidateDataItemNames.VacancyDistance); if (model.ResultsPerPage == 0) { model.ResultsPerPage = GetResultsPerPage(); } UserDataProvider.Push(UserDataItemNames.ResultsPerPage, model.ResultsPerPage.ToString(CultureInfo.InvariantCulture)); if (string.IsNullOrEmpty(model.ApprenticeshipLevel)) { model.ApprenticeshipLevel = GetApprenticeshipLevel(); } UserDataProvider.Push(CandidateDataItemNames.ApprenticeshipLevel, model.ApprenticeshipLevel.ToString(CultureInfo.InvariantCulture)); if (model.SearchAction == SearchAction.Search && model.LocationType != ApprenticeshipLocationType.NonNational) { model.LocationType = ApprenticeshipLocationType.NonNational; } PopulateSortType(model); model.Distances = GetDistances(); model.ResultsPerPageSelectList = GetResultsPerPageSelectList(model.ResultsPerPage); model.ApprenticeshipLevels = GetApprenticeshipLevels(model.ApprenticeshipLevel); model.Categories = GetCategories(); var clientResult = _searchRequestValidator.Validate(model); if (!clientResult.IsValid) { return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Results.ValidationError, new ApprenticeshipSearchResponseViewModel { VacancySearch = model }, clientResult)); } if (!HasGeoPoint(model) && !string.IsNullOrEmpty(model.Location)) { // User did not select a location from the dropdown list, provide suggested locations. var suggestedLocations = _searchProvider.FindLocation(model.Location.Trim()); if (suggestedLocations.HasError()) { return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Results.HasError, new ApprenticeshipSearchResponseViewModel { VacancySearch = model }, suggestedLocations.ViewModelMessage, UserMessageLevel.Warning)); } if (suggestedLocations.Locations.Any()) { var location = suggestedLocations.Locations.First(); model.Location = location.Name; model.Latitude = location.Latitude; model.Longitude = location.Longitude; model.LocationSearches = suggestedLocations.Locations.Skip(1).Select(each => { var vsvm = new ApprenticeshipSearchViewModel { Keywords = model.Keywords, Location = each.Name, Latitude = each.Latitude, Longitude = each.Longitude, PageNumber = model.PageNumber, SortType = model.SortType, WithinDistance = model.WithinDistance, ResultsPerPage = model.ResultsPerPage, Category = model.Category, SubCategories = model.SubCategories, SearchMode = model.SearchMode }; vsvm.Hash = vsvm.LatLonLocHash(); return(vsvm); }).ToArray(); } } var locationResult = _searchLocationValidator.Validate(model); if (!locationResult.IsValid) { return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Results.Ok, new ApprenticeshipSearchResponseViewModel { VacancySearch = model })); } RemoveInvalidSubCategories(model); var searchModel = GetSearchModel(model); PopulateSortType(searchModel); model.SortType = searchModel.SortType; var results = _searchProvider.FindVacancies(searchModel); if (results.VacancySearch != null) { model.SortType = results.VacancySearch.SortType; model.LocationType = results.VacancySearch.LocationType; } results.VacancySearch = model; if (results.HasError()) { return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Results.HasError, new ApprenticeshipSearchResponseViewModel { VacancySearch = model }, results.ViewModelMessage, UserMessageLevel.Warning)); } if (results.ExactMatchFound) { var id = results.Vacancies.Single().Id; return(GetMediatorResponse <ApprenticeshipSearchResponseViewModel>(ApprenticeshipSearchMediatorCodes.Results.ExactMatchFound, parameters: new { id })); } if (model.SearchAction == SearchAction.Search && results.TotalLocalHits > 0) { results.VacancySearch.LocationType = ApprenticeshipLocationType.NonNational; } var isLocalLocationType = results.VacancySearch.LocationType != ApprenticeshipLocationType.National; results.VacancySearch.SortTypes = GetSortTypes(model.SortType, model.Keywords, isLocalLocationType); return(GetMediatorResponse(ApprenticeshipSearchMediatorCodes.Results.Ok, results)); }
public MediatorResponse <TraineeshipSearchResponseViewModel> Results(TraineeshipSearchViewModel model) { UserDataProvider.Pop(CandidateDataItemNames.VacancyDistance); if (model.ResultsPerPage == 0) { model.ResultsPerPage = GetResultsPerPage(); } UserDataProvider.Push(UserDataItemNames.ResultsPerPage, model.ResultsPerPage.ToString(CultureInfo.InvariantCulture)); model.Distances = GetDistances(); model.ResultsPerPageSelectList = GetResultsPerPageSelectList(model.ResultsPerPage); var clientResult = _searchRequestValidator.Validate(model); if (!clientResult.IsValid) { return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.ValidationError, new TraineeshipSearchResponseViewModel { VacancySearch = model }, clientResult)); } if (!HasGeoPoint(model)) { // User did not select a location from the dropdown list, provide suggested locations. var suggestedLocations = _searchProvider.FindLocation(model.Location.Trim()); if (suggestedLocations.HasError()) { return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.HasError, new TraineeshipSearchResponseViewModel { VacancySearch = model }, suggestedLocations.ViewModelMessage, UserMessageLevel.Warning)); } if (suggestedLocations.Locations.Any()) { var location = suggestedLocations.Locations.First(); model.Location = location.Name; model.Latitude = location.Latitude; model.Longitude = location.Longitude; model.LocationSearches = suggestedLocations.Locations.Skip(1).Select(each => { var vsvm = new TraineeshipSearchViewModel { Location = each.Name, Latitude = each.Latitude, Longitude = each.Longitude, PageNumber = model.PageNumber, SortType = model.SortType, WithinDistance = model.WithinDistance, ResultsPerPage = model.ResultsPerPage }; vsvm.Hash = vsvm.LatLonLocHash(); return(vsvm); }).ToArray(); } } var locationResult = _searchLocationValidator.Validate(model); if (!locationResult.IsValid) { return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.Ok, new TraineeshipSearchResponseViewModel { VacancySearch = model })); } var traineeshipSearchResponseViewModel = _searchProvider.FindVacancies(model); traineeshipSearchResponseViewModel.VacancySearch.SortTypes = GetSortTypes(model.SortType); return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.Ok, traineeshipSearchResponseViewModel)); }