public SearchResults <TVacancySummaryResponse, TSearchParameters> Search(TSearchParameters parameters)
        {
            Condition.Requires(parameters).IsNotNull();
            Condition.Requires(parameters.SearchRadius).IsGreaterOrEqual(0);
            Condition.Requires(parameters.PageNumber).IsGreaterOrEqual(1);
            Condition.Requires(parameters.PageSize).IsGreaterOrEqual(1);

            var enterMessage = GetLoggerMessage(CallingMessageFormat, parameters);

            _logger.Debug(enterMessage);

            try
            {
                if (!string.IsNullOrEmpty(parameters.VacancyReference))
                {
                    var exactMatch = _vacancySearchProvider.FindVacancy(parameters.VacancyReference);
                    if (exactMatch != null && exactMatch.Total == 1)
                    {
                        return(exactMatch);
                    }
                }
                return(_vacancySearchProvider.FindVacancies(parameters));
            }
            catch (Exception e)
            {
                var message = GetLoggerMessage(FailedMessageFormat, parameters);
                _logger.Debug(message, e);
                throw new CustomException(message, e, ErrorCodes.VacanciesSearchFailed);
            }
        }
        public void Run()
        {
            var parameters = new ApprenticeshipSearchParameters
            {
                Keywords = string.Empty,
                Location = new Location {
                    GeoPoint = new GeoPoint()
                },
                PageNumber          = 1,
                PageSize            = 10,
                SearchRadius        = 10,
                SortType            = VacancySearchSortType.Distance,
                VacancyLocationType = ApprenticeshipLocationType.National
            };

            _vacancySearchProvider.FindVacancies(parameters);
        }
        public void ProcessCandidateSavedSearches(CandidateSavedSearches candidateSavedSearches)
        {
            var candidateId = candidateSavedSearches.CandidateId;

            var user = _userReadRepository.Get(candidateId);

            if (!user.IsActive())
            {
                return;
            }

            var candidate = _candidateReadRepository.Get(candidateId);

            if (!candidate.ShouldSendSavedSearchAlerts())
            {
                return;
            }

            var savedSearches = _savedSearchReadRepository.GetForCandidate(candidateId);

            if (savedSearches == null || !savedSearches.Any(s => s.AlertsEnabled))
            {
                return;
            }

            foreach (var savedSearch in savedSearches)
            {
                if (!HasGeoLocation(savedSearch))
                {
                    continue;
                }

                var searchParameters = SearchParametersFactory.Create(savedSearch);
                var searchResults    = _vacancySearchProvider.FindVacancies(searchParameters);
                var results          = searchResults.Results.ToList();

                if (results.Count == 0)
                {
                    _logService.Info("Saved search with id {0} returned no results", savedSearch.EntityId);
                    continue;
                }

                var resultsHash = results.GetResultsHash();

                if (savedSearch.LastResultsHash != resultsHash)
                {
                    _logService.Info("Saved search with id {0} returned new results", savedSearch.EntityId);

                    //Results are new
                    savedSearch.LastResultsHash = resultsHash;
                    //todo: once we have the vacancy posted date (March 2015) we may store this instead of the processed date
                    savedSearch.DateProcessed = DateTime.UtcNow;

                    if (savedSearch.AlertsEnabled)
                    {
                        var savedSearchAlert = _savedSearchAlertRepository.GetUnsentSavedSearchAlert(savedSearch) ?? new SavedSearchAlert {
                            Parameters = savedSearch
                        };
                        savedSearchAlert.Results = results;

                        _savedSearchAlertRepository.Save(savedSearchAlert);
                    }

                    _savedSearchWriteRepository.Save(savedSearch);
                }
            }
        }