コード例 #1
0
        protected override bool DoHandle(User user, Candidate candidate)
        {
            Guid entityId;

            if (user == null)
            {
                //If user is null, the candidate should be deleted as an orphaned record
                entityId = candidate.EntityId;
            }
            else
            {
                entityId = user.EntityId;

                //A null candidate record means the user is orphaned and so should be deleted
                if (candidate != null)
                {
                    if (user.Status != UserStatuses.PendingDeletion)
                    {
                        return(false);
                    }

                    if (!user.DateUpdated.HasValue)
                    {
                        return(false);
                    }

                    var housekeepingCyclesSinceDateUpdated = GetHousekeepingCyclesSince(user.DateUpdated.Value);

                    if (housekeepingCyclesSinceDateUpdated < Configuration.HardDeleteAccountAfterCycles)
                    {
                        return(false);
                    }
                }
            }

            var savedSearches = _savedSearchReadRepository.GetForCandidate(entityId);
            var apprenticeshipApplications = _apprenticeshipApplicationReadRepository.GetForCandidate(entityId);
            var traineeshipApplications    = _traineeshipApplicationReadRepository.GetForCandidate(entityId);

            Audit(entityId, user, candidate, savedSearches, apprenticeshipApplications, traineeshipApplications);

            //These methods aren't transactional however the code can cope with missing entities and so will self heal over time in the unlikely event of partial failure

            DeleteApprenticeshipApplications(apprenticeshipApplications);

            DeleteTraineeshipApplications(traineeshipApplications);

            DeleteSavedSearches(savedSearches);

            DeleteCandidate(entityId);

            DeleteAuthentication(entityId);

            DeleteUser(entityId);

            _serviceBus.PublishMessage(new CandidateUserUpdate(entityId, CandidateUserUpdateType.Delete));

            return(true);
        }
コード例 #2
0
        public SavedSearch DeleteSavedSearch(Guid candidateId, Guid savedSearchId)
        {
            var savedSearch = _savedSearchReadRepository
                              .GetForCandidate(candidateId)
                              .FirstOrDefault(each => each.EntityId == savedSearchId);

            if (savedSearch == null)
            {
                return(null);
            }

            _savedSearchWriteRepository.Delete(savedSearchId);

            return(savedSearch);
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
        public IList <SavedSearch> RetrieveSavedSearches(Guid candidateId)
        {
            var savedSearches = _savedSearchReadRepository.GetForCandidate(candidateId);

            return(savedSearches);
        }