public SavedSearch Build() { var savedSearch = new SavedSearch { EntityId = Guid.NewGuid(), SearchMode = _searchMode, Keywords = _keywords, Location = _location, Latitude = _latitude, Longitude = _longitude, WithinDistance = _withinDistance, ApprenticeshipLevel = _apprenticeshipLevel, Category = _category, CategoryFullName = _categoryFullName, SubCategories = _subCategories, SubCategoriesFullName = _subCategoriesFullNames, SearchField = _searchField, AlertsEnabled = _alertsEnabled }; if (savedSearch.HasGeoPoint()) { savedSearch.Hash = savedSearch.GetLatLonLocHash(); } return(savedSearch); }
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 static ApprenticeshipSearchParameters Create(SavedSearch savedSearch) { ApprenticeshipSearchField searchField; if (!Enum.TryParse(savedSearch.SearchField, out searchField)) { searchField = ApprenticeshipSearchField.All; } var location = new Location { Name = savedSearch.Location }; if (savedSearch.HasGeoPoint()) { location.GeoPoint = new GeoPoint { // ReSharper disable PossibleInvalidOperationException HasGeoPoint() checks for this Latitude = savedSearch.Latitude.Value, Longitude = savedSearch.Longitude.Value // ReSharper restore PossibleInvalidOperationException }; } var parameters = new ApprenticeshipSearchParameters { PageNumber = 1, PageSize = 5, Location = location, SearchRadius = savedSearch.WithinDistance, SortType = VacancySearchSortType.RecentlyAdded, ApprenticeshipLevel = savedSearch.ApprenticeshipLevel, VacancyLocationType = ApprenticeshipLocationType.NonNational, SearchField = searchField }; switch (savedSearch.SearchMode) { case ApprenticeshipSearchMode.Keyword: parameters.Keywords = savedSearch.Keywords; break; case ApprenticeshipSearchMode.Category: parameters.CategoryCode = savedSearch.Category; parameters.SubCategoryCodes = savedSearch.SubCategories; parameters.SearchField = ApprenticeshipSearchField.All; break; } return(parameters); }