Beispiel #1
0
        public async Task <WageViewModel> GetWageViewModelAsync(VacancyRouteModel vrm)
        {
            var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_client, _vacancyClient, vrm, RouteNames.Wage_Get);

            var wagePeriod = _minimumWageProvider.GetWagePeriod(vacancy.StartDate.Value);

            var vm = new WageViewModel
            {
                WageType = vacancy.Wage?.WageType,
                FixedWageYearlyAmount               = vacancy.Wage?.FixedWageYearlyAmount?.AsMoney(),
                WageAdditionalInformation           = vacancy.Wage?.WageAdditionalInformation,
                MinimumWageStartFrom                = wagePeriod.ValidFrom.ToMonthNameYearString(),
                NationalMinimumWageLowerBoundHourly = wagePeriod.NationalMinimumWageLowerBound.ToString("C"),
                NationalMinimumWageUpperBoundHourly = wagePeriod.NationalMinimumWageUpperBound.ToString("C"),
                NationalMinimumWageYearly           = GetMinimumWageYearlyText(SFA.DAS.VacancyServices.Wage.WageType.NationalMinimum, vacancy.Wage?.WeeklyHours, vacancy.StartDate.Value),
                ApprenticeshipMinimumWageHourly     = wagePeriod.ApprenticeshipMinimumWage.ToString("C"),
                ApprenticeshipMinimumWageYearly     = GetMinimumWageYearlyText(SFA.DAS.VacancyServices.Wage.WageType.ApprenticeshipMinimum, vacancy.Wage?.WeeklyHours, vacancy.StartDate.Value),
                WeeklyHours = vacancy.Wage.WeeklyHours.Value,
                PageInfo    = Utility.GetPartOnePageInfo(vacancy)
            };

            if (vacancy.Status == VacancyStatus.Referred)
            {
                vm.Review = await _reviewSummaryService.GetReviewSummaryViewModelAsync(vacancy.VacancyReference.Value,
                                                                                       ReviewFieldMappingLookups.GetWageReviewFieldIndicators());
            }

            return(vm);
        }
        internal static IRuleBuilderInitial <Vacancy, Vacancy> FixedWageMustBeGreaterThanApprenticeshipMinimumWage(this IRuleBuilder <Vacancy, Vacancy> ruleBuilder, IMinimumWageProvider minimumWageService)
        {
            return(ruleBuilder.Custom((vacancy, context) =>
            {
                var wagePeriod = minimumWageService.GetWagePeriod(vacancy.StartDate.Value);

                if (vacancy.Wage.FixedWageYearlyAmount == null || vacancy.Wage.FixedWageYearlyAmount / 52 / vacancy.Wage.WeeklyHours < wagePeriod.ApprenticeshipMinimumWage)
                {
                    var minimumYearlyWageForApprentices = WagePresenter.GetDisplayText(WageType.ApprenticeshipMinimum, WageUnit.Annually, new WageDetails
                    {
                        HoursPerWeek = vacancy.Wage.WeeklyHours,
                        StartDate = vacancy.StartDate.Value
                    }).AsWholeMoneyAmount();

                    var errorMessage = (vacancy.Status == VacancyStatus.Live) ?
                                       $"National Minimum Wage is changing from {wagePeriod.ValidFrom:d MMM yyyy}. So the fixed wage you entered before will no longer be valid. Change the date to before {wagePeriod.ValidFrom:d MMM yyyy} or to change the wage, create a new vacancy." :
                                       $"Yearly wage must be at least {minimumYearlyWageForApprentices}";

                    var failure = new ValidationFailure(string.Empty, errorMessage)
                    {
                        ErrorCode = "49",
                        CustomState = VacancyRuleSet.MinimumWage,
                        PropertyName = $"{nameof(Wage)}.{nameof(Wage.FixedWageYearlyAmount)}"
                    };
                    context.AddFailure(failure);
                }
            }));
        }
        public async Task <SearchResultPreviewViewModel> GetSearchResultPreviewViewModelAsync(VacancyRouteModel vrm)
        {
            var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_client, _vacancyClient, vrm, RouteNames.SearchResultPreview_Get);

            var wagePeriod = _wageProvider.GetWagePeriod(vacancy.StartDate.Value);

            var vm = new SearchResultPreviewViewModel
            {
                EmployerName      = vacancy.EmployerName,
                NumberOfPositions = vacancy.NumberOfPositions?.ToString(),
                ShortDescription  = vacancy.ShortDescription,
                ClosingDate       = vacancy.ClosingDate?.AsGdsDate(),
                StartDate         = vacancy.StartDate?.AsGdsDate(),
                LevelName         = await GetLevelName(vacancy.ProgrammeId),
                Title             = vacancy.Title,
                Wage                  = vacancy.Wage?.ToText(vacancy.StartDate),
                HasYearlyWage         = (vacancy.Wage != null && vacancy.Wage.WageType != WageType.Unspecified),
                IsDisabilityConfident = vacancy.IsDisabilityConfident
            };

            if (vacancy.EmployerLocation != null)
            {
                vm.MapUrl = vacancy.EmployerLocation.HasGeocode
                    ? _mapService.GetMapImageUrl(vacancy.EmployerLocation.Latitude.ToString(), vacancy.EmployerLocation.Longitude.ToString(), MapImageWidth, MapImageHeight)
                    : _mapService.GetMapImageUrl(vacancy.EmployerLocation?.Postcode, MapImageWidth, MapImageHeight);
            }

            return(vm);
        }
        internal static IRuleBuilderInitial <Vacancy, Vacancy> FixedWageMustBeGreaterThanApprenticeshipMinimumWage(this IRuleBuilder <Vacancy, Vacancy> ruleBuilder, IMinimumWageProvider minimumWageService)
        {
            return(ruleBuilder.Custom((vacancy, context) =>
            {
                var wagePeriod = minimumWageService.GetWagePeriod(vacancy.StartDate.Value);

                if (vacancy.Wage.FixedWageYearlyAmount == null || vacancy.Wage.FixedWageYearlyAmount / 52 / vacancy.Wage.WeeklyHours < wagePeriod.ApprenticeshipMinimumWage)
                {
                    var errorMessage = (vacancy.Status == VacancyStatus.Live) ?
                                       $"National Minimum Wage is changing from {wagePeriod.ValidFrom:d MMM yyyy}. So the fixed wage you entered before will no longer be valid. Change the date to before {wagePeriod.ValidFrom:d MMM yyyy} or to change the wage, create a new vacancy." :
                                       $"The wage should not be less than the new National Minimum Wage for apprentices effective from {wagePeriod.ValidFrom:d MMM yyyy}";

                    var failure = new ValidationFailure(string.Empty, errorMessage)
                    {
                        ErrorCode = "49",
                        CustomState = VacancyRuleSet.MinimumWage
                    };
                    context.AddFailure(failure);
                }
            }));
        }
Beispiel #5
0
        public async Task <ReviewViewModel> Map(VacancyReview review)
        {
            var vacancy = review.VacancySnapshot;

            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());

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

            var programme = programmeTask.Result;

            var historiesVm = GetReviewHistoriesViewModel(reviewHistoryTask.Result);

            var wagePeriod = _wageProvider.GetWagePeriod(vacancy.StartDate.Value);

            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.ContactName             = vacancy.EmployerContact?.Name;
                vm.ContactEmail            = vacancy.EmployerContact?.Email;
                vm.ContactTelephone        = vacancy.EmployerContact?.Phone;
                vm.ClosingDate             = vacancy.ClosingDate?.AsGdsDate();
                vm.EmployerDescription     = vacancy.EmployerDescription;
                vm.EmployerName            = vacancy.EmployerName;
                vm.EmployerWebsiteUrl      = vacancy.EmployerWebsiteUrl;
                SetEmployerAddressElements(vm, vacancy);
                vm.IsDisabilityConfident    = vacancy.IsDisabilityConfident;
                vm.NumberOfPositionsCaption = $"{"position".ToQuantity(vacancy.NumberOfPositions.Value)} available";
                vm.OutcomeDescription       = vacancy.OutcomeDescription;
                vm.PossibleStartDate        = vacancy.StartDate?.AsGdsDate();
                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.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.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);
                }

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

            return(vm);
        }