public CandidateApplicationsViewModel GetCandidateApplications(Guid candidateId)
        {
            var webSettings = _configurationService.Get <CommonWebConfiguration>();
            var domainUrl   = webSettings.SiteDomainName;

            _logService.Debug("Calling CandidateApprenticeshipApplicationProvider to get the applications for candidate ID: {0}.",
                              candidateId);

            try
            {
                var candidate     = _candidateApplicationService.GetCandidate(candidateId);
                var candidateName =
                    new Name(candidate.RegistrationDetails.FirstName, candidate.RegistrationDetails.MiddleNames,
                             candidate.RegistrationDetails.LastName).GetDisplayText();

                var apprenticeshipApplicationSummaries = _candidateApplicationService.GetApprenticeshipApplications(candidateId);
                var apprenticeshipApplications         = apprenticeshipApplicationSummaries
                                                         .Select(each => new CandidateApprenticeshipApplicationViewModel(each))
                                                         .ToList();

                var traineeshipApplicationSummaries = _candidateApplicationService.GetTraineeshipApplications(candidateId);
                var traineeshipApplications         = traineeshipApplicationSummaries
                                                      .Select(each => new CandidateTraineeshipApplicationViewModel
                {
                    ApplicationId = each.ApplicationId,
                    VacancyId     = each.LegacyVacancyId,
                    VacancyStatus = each.VacancyStatus,
                    Title         = each.Title,
                    EmployerName  = each.EmployerName,
                    IsArchived    = each.IsArchived,
                    DateApplied   = each.DateApplied
                })
                                                      .ToList();

                return(new CandidateApplicationsViewModel
                {
                    CandidateId = candidateId,
                    CandidateName = candidateName,
                    CandidateApprenticeshipApplications = apprenticeshipApplications,
                    CandidateTraineeshipApplications = traineeshipApplications,
                    NextStepUrl = string.Format($"https://{domainUrl}/nextsteps")
                });
            }
            catch (Exception e)
            {
                var message = $"Get MyApplications failed for candidate ID: {candidateId}.";

                _logService.Error(message, e);

                throw;
            }
        }
Exemple #2
0
        private TraineeshipFeatureViewModel GetTraineeshipFeatureViewModel(Guid candidateId, IList <ApprenticeshipApplicationSummary> apprenticeshipApplicationSummaries, IList <TraineeshipApplicationSummary> traineeshipApplicationSummaries)
        {
            var candididate = _candidateApplicationService.GetCandidate(candidateId);

            var webConfiguration = _configurationService.Get <CommonWebConfiguration>();
            var unsuccessfulApplicationsToShowTraineeshipsPrompt = webConfiguration.UnsuccessfulApplicationsToShowTraineeshipsPrompt;
            var allowTraineeshipPrompts = candididate.CommunicationPreferences.AllowTraineeshipPrompts;

            var sufficentUnsuccessfulApprenticeshipApplicationsToPrompt = apprenticeshipApplicationSummaries.Count(each => each.Status == ApplicationStatuses.Unsuccessful) >= unsuccessfulApplicationsToShowTraineeshipsPrompt;
            var candidateHasSuccessfulApprenticeshipApplication         = apprenticeshipApplicationSummaries.Any(each => each.Status == ApplicationStatuses.Successful);
            var candidateHasAppliedForTraineeship = traineeshipApplicationSummaries.Any();

            var viewModel = new TraineeshipFeatureViewModel
            {
                ShowTraineeshipsPrompt = allowTraineeshipPrompts && sufficentUnsuccessfulApprenticeshipApplicationsToPrompt && !candidateHasSuccessfulApprenticeshipApplication && !candidateHasAppliedForTraineeship,
                ShowTraineeshipsLink   = (sufficentUnsuccessfulApprenticeshipApplicationsToPrompt || candidateHasAppliedForTraineeship)
            };

            return(viewModel);
        }
        private List <ApplicationSummary> SearchCandidateApplications(VacancyApplicationsSearchViewModel vacancyApplicationsSearch, List <ApplicationSummary> applications)
        {
            if (!vacancyApplicationsSearch.IsCandidateSearch())
            {
                return(applications);
            }

            var applicantId = CandidateSearchExtensions.GetCandidateId(vacancyApplicationsSearch.ApplicantId);

            if (applicantId.HasValue)
            {
                var candidate = _candidateApplicationService.GetCandidate(applicantId.Value, false);
                if (candidate != null)
                {
                    return(applications.Where(a => a.CandidateId == candidate.EntityId).ToList());
                }
                return(new List <ApplicationSummary>());
            }

            var candidateGuidPrefix = CandidateSearchExtensions.GetCandidateGuidPrefix(vacancyApplicationsSearch.ApplicantId);

            if (!string.IsNullOrEmpty(candidateGuidPrefix))
            {
                return(applications.Where(a => a.CandidateId.ToString().StartsWith(candidateGuidPrefix, StringComparison.InvariantCultureIgnoreCase)).ToList());
            }

            if (!string.IsNullOrEmpty(vacancyApplicationsSearch.ApplicantId))
            {
                //Attempt to search by an unrecognised application id. Return no results
                return(new List <ApplicationSummary>());
            }

            return
                (applications.Where(
                     a =>
                     (string.IsNullOrEmpty(vacancyApplicationsSearch.FirstName) || a.CandidateDetails.FirstName.StartsWith(vacancyApplicationsSearch.FirstName, StringComparison.InvariantCultureIgnoreCase)) &&
                     (string.IsNullOrEmpty(vacancyApplicationsSearch.LastName) || a.CandidateDetails.LastName.StartsWith(vacancyApplicationsSearch.LastName, StringComparison.InvariantCultureIgnoreCase)) &&
                     (string.IsNullOrEmpty(vacancyApplicationsSearch.Postcode) || a.CandidateDetails.Address.Postcode.Replace(" ", "").StartsWith(vacancyApplicationsSearch.Postcode.Replace(" ", ""), StringComparison.InvariantCultureIgnoreCase))
                     ).ToList());
        }