Exemplo n.º 1
0
        public async Task <ReviewViewModel> Map(VacancyReview review)
        {
            var vacancy = review.VacancySnapshot;

            var currentVacancy = _vacancyClient.GetVacancyAsync(review.VacancyReference);

            var programmeTask = _vacancyClient.GetApprenticeshipProgrammeAsync(vacancy.ProgrammeId);

            var reviewHistoryTask = _vacancyClient.GetVacancyReviewHistoryAsync(review.VacancyReference);

            var approvedCountTask = _vacancyClient.GetApprovedCountAsync(vacancy.SubmittedByUser.UserId);

            var approvedFirstTimeCountTask = _vacancyClient.GetApprovedFirstTimeCountAsync(vacancy.SubmittedByUser.UserId);

            var reviewSummaryTask = _reviewSummaryService.GetReviewSummaryViewModelAsync(review.Id,
                                                                                         ReviewFieldMappingLookups.GetPreviewReviewFieldIndicators());

            var anonymousApprovedCountTask = vacancy.IsAnonymous ? _vacancyClient.GetAnonymousApprovedCountAsync(vacancy.LegalEntityId) : Task.FromResult(0);

            await Task.WhenAll(
                currentVacancy, programmeTask,
                approvedCountTask,
                approvedFirstTimeCountTask,
                reviewHistoryTask,
                reviewSummaryTask,
                anonymousApprovedCountTask);

            var programme = programmeTask.Result;

            var currentVacancyResult = currentVacancy.Result;

            var historiesVm = GetReviewHistoriesViewModel(reviewHistoryTask.Result);

            var vm = new ReviewViewModel();

            vm.Review = reviewSummaryTask.Result;
            try
            {
                vm.SubmittedByName         = vacancy.SubmittedByUser.Name;
                vm.SubmittedByEmail        = vacancy.SubmittedByUser.Email;
                vm.ApplicationInstructions = vacancy.ApplicationInstructions;
                vm.ApplicationMethod       = vacancy.ApplicationMethod.Value;
                vm.ApplicationUrl          = vacancy.ApplicationUrl;
                vm.ClosingDate             = vacancy.ClosingDate?.AsGdsDate();
                vm.EducationLevelName      =
                    EducationLevelNumberHelper.GetEducationLevelNameOrDefault(programme.EducationLevelNumber, programme.Level);
                vm.EmployerContactName      = vacancy.EmployerContact?.Name;
                vm.EmployerContactEmail     = vacancy.EmployerContact?.Email;
                vm.EmployerContactTelephone = vacancy.EmployerContact?.Phone;
                vm.EmployerDescription      = vacancy.EmployerDescription;
                vm.EmployerName             = vacancy.EmployerName;
                vm.EmployerNameOption       = vacancy.EmployerNameOption.Value;
                vm.AnonymousReason          = vacancy.AnonymousReason;
                vm.AnonymousApprovedCount   = anonymousApprovedCountTask.Result;
                vm.EmployerWebsiteUrl       = vacancy.EmployerWebsiteUrl;
                vm.MapUrl = MapImageHelper.GetEmployerLocationMapUrl(vacancy, _mapService, MapImageWidth, MapImageHeight);
                vm.EmployerAddressElements  = vacancy.EmployerAddressForDisplay();
                vm.LegalEntityName          = vacancy.LegalEntityName;
                vm.IsDisabilityConfident    = vacancy.IsDisabilityConfident;
                vm.NumberOfPositionsCaption = $"{"position".ToQuantity(vacancy.NumberOfPositions.Value)} available";
                vm.OutcomeDescription       = vacancy.OutcomeDescription;
                vm.PossibleStartDate        = vacancy.StartDate?.AsGdsDate();
                vm.ProviderContactName      = vacancy.ProviderContact?.Name;
                vm.ProviderContactEmail     = vacancy.ProviderContact?.Email;
                vm.ProviderContactTelephone = vacancy.ProviderContact?.Phone;
                vm.ProviderName             = vacancy.TrainingProvider.Name;
                vm.Qualifications           = vacancy.Qualifications.SortQualifications(_qualifications.Value).AsText();
                vm.ShortDescription         = vacancy.ShortDescription;
                vm.Skills                 = vacancy.Skills ?? Enumerable.Empty <string>();
                vm.OwnerType              = vacancy.OwnerType;
                vm.ThingsToConsider       = vacancy.ThingsToConsider;
                vm.Title                  = vacancy.Title;
                vm.TrainingDescription    = vacancy.TrainingDescription;
                vm.VacancyDescription     = vacancy.Description;
                vm.VacancyReferenceNumber = $"VAC{vacancy.VacancyReference}";
                vm.TrainingTitle          = programme.Title;
                vm.TrainingType           = programme.ApprenticeshipType.GetDisplayName();
                vm.TrainingLevel          = programme.Level.GetDisplayName();
                vm.Level                  = programme.Level;
                vm.ExpectedDuration       = (vacancy.Wage.DurationUnit.HasValue && vacancy.Wage.Duration.HasValue)
                    ? vacancy.Wage.DurationUnit.Value.GetDisplayName().ToQuantity(vacancy.Wage.Duration.Value)
                    : null;
                vm.HoursPerWeek = $"{vacancy.Wage.WeeklyHours:0.##}";
                vm.WageInfo     = vacancy.Wage.WageAdditionalInformation;
                vm.WageText     = vacancy.StartDate.HasValue
                    ? vacancy.Wage.ToText(vacancy.StartDate)
                    : null;
                vm.WorkingWeekDescription               = vacancy.Wage.WorkingWeekDescription;
                vm.SubmittedDate                        = vacancy.SubmittedDate.Value;
                vm.VacancyReviewsApprovedCount          = approvedCountTask.Result;
                vm.VacancyReviewsApprovedFirstTimeCount = approvedFirstTimeCountTask.Result;

                vm.FieldIdentifiers = await GetFieldIdentifiersViewModel(review);

                vm.ReviewerComment = review.ManualQaComment;
                vm.ReviewHistories = historiesVm;
                vm.IsResubmission  = review.SubmissionCount > 1;

                vm.ReviewerName = review.ReviewedByUser.Name;
                vm.ReviewedDate = review.ReviewedDate.GetValueOrDefault();

                vm.ManualOutcome = review.ManualOutcome;

                if (review.Status == ReviewStatus.Closed)
                {
                    vm.PageTitle = GetPageTitle(historiesVm, review.Id, review.ManualOutcome, currentVacancyResult);
                }

                vm.AutomatedQaResults = GetAutomatedQaResultViewModel(review);
                vm.IsVacancyDeleted   = currentVacancyResult.IsDeleted;
            }
            catch (NullReferenceException ex)
            {
                _logger.LogError(ex, "Unable to map vacancy to view model. Unexpected null fields.");
                throw;
            }

            return(vm);
        }
Exemplo n.º 2
0
        public async Task MapFromVacancyAsync(DisplayVacancyViewModel vm, Vacancy vacancy)
        {
            var programme = await _vacancyClient.GetApprenticeshipProgrammeAsync(vacancy.ProgrammeId);

            var allQualifications = await _vacancyClient.GetCandidateQualificationsAsync();

            vm.ApplicationMethod       = vacancy.ApplicationMethod;
            vm.ApplicationInstructions = vacancy.ApplicationInstructions;
            vm.ApplicationUrl          = vacancy.ApplicationUrl;
            vm.CanDelete          = vacancy.CanDelete;
            vm.CanSubmit          = vacancy.CanSubmit;
            vm.ClosingDate        = (vacancy.ClosedDate ?? vacancy.ClosingDate)?.AsGdsDate();
            vm.EducationLevelName =
                EducationLevelNumberHelper.GetEducationLevelNameOrDefault(programme.EducationLevelNumber, programme.ApprenticeshipLevel);
            vm.EmployerDescription = vacancy.EmployerDescription;
            vm.EmployerName        = await _vacancyClient.GetEmployerNameAsync(vacancy);

            vm.EmployerWebsiteUrl       = vacancy.EmployerWebsiteUrl;
            vm.EmployerAddressElements  = Enumerable.Empty <string>();
            vm.FindAnApprenticeshipUrl  = _externalLinksConfiguration.FindAnApprenticeshipUrl;
            vm.IsAnonymous              = vacancy.IsAnonymous;
            vm.NumberOfPositions        = vacancy.NumberOfPositions?.ToString();
            vm.NumberOfPositionsCaption = vacancy.NumberOfPositions.HasValue
                ? $"{"position".ToQuantity(vacancy.NumberOfPositions.Value)} available"
                : null;
            vm.OutcomeDescription       = vacancy.OutcomeDescription;
            vm.PossibleStartDate        = vacancy.StartDate?.AsGdsDate();
            vm.ProviderContactName      = vacancy.ProviderContact?.Name;
            vm.ProviderContactEmail     = vacancy.ProviderContact?.Email;
            vm.ProviderContactTelephone = vacancy.ProviderContact?.Phone;
            vm.ProviderName             = vacancy.TrainingProvider?.Name;
            vm.Qualifications           = vacancy.Qualifications.SortQualifications(allQualifications).AsText();
            vm.ShortDescription         = vacancy.ShortDescription;
            vm.Skills                 = vacancy.Skills ?? Enumerable.Empty <string>();
            vm.ThingsToConsider       = vacancy.ThingsToConsider;
            vm.Title                  = vacancy.Title;
            vm.TrainingDescription    = vacancy.TrainingDescription;
            vm.VacancyDescription     = vacancy.Description;
            vm.VacancyReferenceNumber = vacancy.VacancyReference.HasValue
                                        ? $"VAC{vacancy.VacancyReference.ToString()}"
                                        : string.Empty;
            vm.IsDisabilityConfident = vacancy.IsDisabilityConfident;

            if (vacancy.EmployerLocation != null)
            {
                vm.MapUrl = MapImageHelper.GetEmployerLocationMapUrl(vacancy, _mapService, MapImageWidth, MapImageHeight);

                vm.EmployerAddressElements = vacancy.EmployerAddressForDisplay();
            }

            if (vacancy.ProgrammeId != null)
            {
                vm.TrainingTitle = programme?.Title;
                vm.TrainingType  = programme?.ApprenticeshipType.GetDisplayName();
                vm.TrainingLevel = programme?.ApprenticeshipLevel.GetDisplayName();
            }

            if (vacancy.Wage != null)
            {
                vm.ExpectedDuration = (vacancy.Wage.DurationUnit.HasValue && vacancy.Wage.Duration.HasValue)
                    ? vacancy.Wage.DurationUnit.Value.GetDisplayName().ToQuantity(vacancy.Wage.Duration.Value)
                    : null;
                vm.HoursPerWeek           = $"{vacancy.Wage.WeeklyHours:0.##}";
                vm.WageInfo               = vacancy.Wage.WageAdditionalInformation;
                vm.WageText               = vacancy.StartDate.HasValue ? vacancy.Wage.ToText(vacancy.StartDate) : null;
                vm.WorkingWeekDescription = vacancy.Wage.WorkingWeekDescription;
            }
        }