示例#1
0
        public void SendSavedSearchAlerts(Guid batchId)
        {
            var allCandidatesSavedSearchAlerts = _savedSearchAlertRepository.GetCandidatesSavedSearchAlerts();

            foreach (var candidateId in allCandidatesSavedSearchAlerts.Keys)
            {
                var candidate = _candidateReadRepository.Get(candidateId);
                var user      = _userReadRepository.Get(candidateId);

                var candidateSavedSearchAlerts = allCandidatesSavedSearchAlerts[candidateId];

                if (candidate.AllowsCommunication() && user.IsActive())
                {
                    var communicationRequest = CommunicationRequestFactory.GetSavedSearchAlertCommunicationRequest(candidate, candidateSavedSearchAlerts);

                    _serviceBus.PublishMessage(communicationRequest);

                    // Update candidates saved search alerts to sent
                    candidateSavedSearchAlerts.ToList().ForEach(dd =>
                    {
                        dd.BatchId = batchId;
                        _savedSearchAlertRepository.Save(dd);
                    });
                }
                else
                {
                    // Soft delete candidates saved search status alerts by setting batch id to empty
                    candidateSavedSearchAlerts.ToList().ForEach(dd =>
                    {
                        dd.BatchId = Guid.Empty;
                        _savedSearchAlertRepository.Save(dd);
                    });
                }
            }
        }
        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);
                }
            }
        }