private bool HasGeoLocation(SavedSearch savedSearch) { if (!savedSearch.HasGeoPoint()) { var locations = _locationSearchService.FindLocation(savedSearch.Location); var locationsList = locations == null ? new List <Location>() : locations.ToList(); if (locationsList.Any()) { var location = locationsList.First(); _logService.Info("Location {0} specified in saved search with id {1} was identified as {2}", savedSearch.Location, savedSearch.EntityId, location.Name); savedSearch.Location = location.Name; savedSearch.Latitude = location.GeoPoint.Latitude; savedSearch.Longitude = location.GeoPoint.Longitude; savedSearch.Hash = savedSearch.GetLatLonLocHash(); //Update saved search now we know the lat/long/hash _savedSearchWriteRepository.Save(savedSearch); } else { _logService.Info("Location {0} specified in saved search with id {1} could not be found", savedSearch.Location, savedSearch.EntityId); return(false); } } return(true); }
public SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters> GetSuggestedApprenticeshipVacancies( ApprenticeshipSearchParameters searchParameters, IList <ApprenticeshipApplicationSummary> candidateApplications, int vacancyId) { var vacancy = _vacancyDataProvider.GetVacancyDetails(vacancyId); var vacancySubCategory = _referenceDataService.GetSubCategoryByName(vacancy.SubCategory); if (vacancySubCategory == null) { return(null); } searchParameters.CategoryCode = vacancySubCategory.ParentCategoryCodeName; searchParameters.SubCategoryCodes = new[] { vacancySubCategory.CodeName }; var excludeVacancyIds = candidateApplications.Select(x => x.LegacyVacancyId).ToList(); excludeVacancyIds.Add(vacancyId); searchParameters.ExcludeVacancyIds = excludeVacancyIds; if (searchParameters.Location != null) { if (searchParameters.Location.GeoPoint == null || (searchParameters.Location.GeoPoint.Latitude == 0 && searchParameters.Location.GeoPoint.Longitude == 0)) { var locations = _locationSearchService.FindLocation(searchParameters.Location.Name); searchParameters.Location = locations != null?locations.FirstOrDefault() : null; } } if (searchParameters.Location == null) { searchParameters.Location = new Location { Name = vacancy.VacancyAddress.Postcode, GeoPoint = new GeoPoint { Latitude = vacancy.VacancyAddress.GeoPoint.Latitude, Longitude = vacancy.VacancyAddress.GeoPoint.Longitude, } }; } var searchResults = _searchService.Search(searchParameters); if (searchResults.Total == 0) { //Widen search to category alone searchParameters.SubCategoryCodes = null; searchResults = _searchService.Search(searchParameters); } return(searchResults); }
public LocationsViewModel FindLocation(string placeNameOrPostcode) { _logger.Debug("Calling SearchProvider to find the location for place name or postcode: {0}", placeNameOrPostcode); try { var locations = _locationSearchService.FindLocation(placeNameOrPostcode); if (locations == null) { return(new LocationsViewModel()); } return(new LocationsViewModel( _apprenticeshipSearchMapper.Map <IEnumerable <Location>, IEnumerable <LocationViewModel> >(locations))); } catch (CustomException e) { string message, errorMessage; switch (e.Code) { case ErrorCodes.LocationLookupFailed: errorMessage = string.Format("Location lookup failed for place name {0}", placeNameOrPostcode); message = VacancySearchResultsPageMessages.LocationLookupFailed; break; default: errorMessage = string.Format("Postcode lookup failed for postcode {0}", placeNameOrPostcode); message = VacancySearchResultsPageMessages.PostcodeLookupFailed; break; } _logger.Error(errorMessage, e); return(new LocationsViewModel(message)); } catch (Exception e) { var message = string.Format("Find location failed for place name or postcode {0}", placeNameOrPostcode); _logger.Error(message, e); throw; } }