public async Task <ActionResult> Location(string term) { return(await Task.Run <ActionResult>(() => { if (Request.IsAjaxRequest()) { var result = string.IsNullOrWhiteSpace(term) ? new LocationsViewModel(new List <LocationViewModel>()) : _searchProvider.FindLocation(term); return Json(result.Locations.Take(_locationResultLimit), JsonRequestBehavior.AllowGet); } throw new NotSupportedException("Non-JS not yet implemented!"); })); }
public ActionResult Index() { var statusTasks = new[] { new Task(() => _apprenticeshipApplicationProvider.GetApplicationViewModel(Guid.NewGuid(), 123456)), new Task(() => _candidateServiceProvider.GetCandidate(Guid.NewGuid())), new Task(() => _searchProvider.FindLocation("London")) }; Parallel.ForEach(statusTasks, task => task.Start()); Task.WaitAll(statusTasks); // GDS Performance platform (Pingdom) is configured to look for the following text // in a 200 response. Anything other than this will register the site as down. return(Content("System healthy.")); }
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(false); 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. if (model.Location != null) { 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 })); } UserDataProvider.Push(UserDataItemNames.LastSearchedLocation, string.Join("|", model.Location, model.Latitude, model.Longitude)); var traineeshipSearchResponseViewModel = _traineeshipVacancyProvider.FindVacancies(model); traineeshipSearchResponseViewModel.VacancySearch = model; if (traineeshipSearchResponseViewModel.ExactMatchFound) { var id = traineeshipSearchResponseViewModel.Vacancies.Single().Id; return(GetMediatorResponse <TraineeshipSearchResponseViewModel>(TraineeshipSearchMediatorCodes.Results.ExactMatchFound, parameters: new { id })); } if (traineeshipSearchResponseViewModel.VacancySearch != null) { traineeshipSearchResponseViewModel.VacancySearch.SortTypes = GetSortTypes(model.SortType); } if (traineeshipSearchResponseViewModel.HasError()) { return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.HasError, new TraineeshipSearchResponseViewModel { VacancySearch = model }, traineeshipSearchResponseViewModel.ViewModelMessage, UserMessageLevel.Warning)); } return(GetMediatorResponse(TraineeshipSearchMediatorCodes.Results.Ok, traineeshipSearchResponseViewModel)); }