public async Task <OrchestratorResponse> PostLocationEditModelAsync(LocationEditModel m, VacancyUser user, long ukprn)
        {
            var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_providerVacancyClient,
                                                                         _recruitVacancyClient, m, RouteNames.Location_Post);

            var employerVacancyInfo = await _providerVacancyClient.GetProviderEmployerVacancyDataAsync(ukprn, vacancy.EmployerAccountId);

            var selectedLegalEntity = employerVacancyInfo.LegalEntities.SingleOrDefault(x => x.LegalEntityId == m.SelectedLegalEntityId);

            vacancy.LegalEntityId = m.SelectedLegalEntityId;

            vacancy.EmployerLocation = new Vacancies.Client.Domain.Entities.Address
            {
                AddressLine1 = m.AddressLine1,
                AddressLine2 = m.AddressLine2,
                AddressLine3 = m.AddressLine3,
                AddressLine4 = m.AddressLine4,
                Postcode     = m.Postcode.AsPostcode(),
                Latitude     = null,
                Longitude    = null
            };

            return(await ValidateAndExecute(
                       vacancy,
                       v => _recruitVacancyClient.Validate(v, ValidationRules),
                       v => _recruitVacancyClient.UpdateDraftVacancyAsync(vacancy, user)));
        }
Beispiel #2
0
        private async Task <List <OrganisationViewModel> > GetLegalEntityViewModelsAsync(long ukprn, string employerAccountId)
        {
            var info = await _providerVacancyClient.GetProviderEmployerVacancyDataAsync(ukprn, employerAccountId);

            if (info == null || !info.LegalEntities.Any())
            {
                _logger.LogWarning("No legal entities found for {employerAccountId}", employerAccountId);
                return(new List <OrganisationViewModel>());
            }

            return(info.LegalEntities.Select(ConvertToOrganisationViewModel).ToList());
        }
Beispiel #3
0
        public async Task <OrchestratorResponse> PostLocationEditModelAsync(
            LocationEditModel locationEditModel, VacancyUser user, long ukprn,
            VacancyEmployerInfoModel employerInfoModel)
        {
            if (string.IsNullOrEmpty(locationEditModel.SelectedLocation))
            {
                return(new OrchestratorResponse(false));
            }

            var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_providerVacancyClient,
                                                                         _recruitVacancyClient, locationEditModel, RouteNames.Location_Post);

            var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId)
                ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId;

            var employerVacancyInfoTask = _providerVacancyClient.GetProviderEmployerVacancyDataAsync(ukprn, vacancy.EmployerAccountId);
            var employerProfileTask     = _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId);
            await Task.WhenAll(employerProfileTask, employerVacancyInfoTask);

            var employerVacancyInfo  = employerVacancyInfoTask.Result;
            var employerProfile      = employerProfileTask.Result;
            var selectedOrganisation = employerVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId);
            var allLocations         = await GetAllAvailableLocationsAsync(employerProfile, vacancy, ukprn);

            var newLocation =
                locationEditModel.SelectedLocation == LocationViewModel.UseOtherLocationConst
                    ? locationEditModel.ToAddressString()
                    : locationEditModel.SelectedLocation;

            var matchingAddress = GetMatchingAddress(newLocation, allLocations);

            vacancy.EmployerLocation = matchingAddress ?? ConvertToDomainAddress(locationEditModel);

            //if cookie is found update legal entity and name option
            if (employerInfoModel != null)
            {
                vacancy.LegalEntityName = selectedOrganisation.Name;
                vacancy.AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId;
                vacancy.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption();
                vacancy.AnonymousReason    = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null;
                vacancy.EmployerName       = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null;
            }

            return(await ValidateAndExecute(
                       vacancy,
                       v => _recruitVacancyClient.Validate(v, ValidationRules),
                       async v =>
            {
                await _recruitVacancyClient.UpdateDraftVacancyAsync(vacancy, user);
                await UpdateEmployerProfileAsync(employerInfoModel, employerProfile, matchingAddress == null ? vacancy.EmployerLocation : null, user);
            }));
        }
Beispiel #4
0
        public async Task <VacancyReviewedConfirmationViewModel> GetVacancyReviewedOrchestratorConfirmationViewModelAsync(VacancyRouteModel vrm, VacancyUser vacancyUser)
        {
            var vacancy = await Utility.GetAuthorisedVacancyAsync(_client, _vacancyClient, vrm, RouteNames.Reviewed_Index_Get);

            var employer = await _client.GetProviderEmployerVacancyDataAsync(vrm.Ukprn, vacancy.EmployerAccountId);

            var preferences = await _vacancyClient.GetUserNotificationPreferencesAsync(vacancyUser.UserId);

            if (vacancy.Status != VacancyStatus.Review)
            {
                throw new InvalidStateException(string.Format(ErrorMessages.VacancyNotReviewedSuccessfully, vacancy.Title));
            }

            var vm = new VacancyReviewedConfirmationViewModel
            {
                Title            = vacancy.Title,
                VacancyReference = vacancy.VacancyReference?.ToString(),
                EmployerName     = employer.Name,
                IsResubmit       = vacancy.ReviewCount > 1,
                IsVacancyRejectedByEmployerNotificationSelected = preferences.NotificationTypes.HasFlag(NotificationTypes.VacancyRejectedByEmployer)
            };

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

            var employer = await _client.GetProviderEmployerVacancyDataAsync(vacancy.TrainingProvider.Ukprn.Value, vacancy.EmployerAccountId);

            var allQualifications = await _vacancyClient.GetCandidateQualificationsAsync();

            vm.Status                  = vacancy.Status;
            vm.AccountName             = employer.Name;
            vm.ApplicationMethod       = vacancy.ApplicationMethod;
            vm.ApplicationInstructions = vacancy.ApplicationInstructions;
            vm.ApplicationUrl          = vacancy.ApplicationUrl;
            vm.CanDelete               = vacancy.CanDelete;
            vm.CanSubmit               = vacancy.CanSubmit;
            vm.IsSentForReview         = vacancy.Status == VacancyStatus.Review;
            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.EmployerRejectedReason        = vacancy.EmployerRejectedReason;
            vm.EmployerReviewFieldIndicators = vacancy.EmployerReviewFieldIndicators;
            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}"
                                        : 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;
            }
        }
Beispiel #6
0
        public async Task <OrchestratorResponse> PostLocationEditModelAsync(
            LocationEditModel locationEditModel, VacancyUser user, long ukprn,
            VacancyEmployerInfoModel employerInfoModel)
        {
            if (string.IsNullOrEmpty(locationEditModel.SelectedLocation))
            {
                return(new OrchestratorResponse(false));
            }

            var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_providerVacancyClient,
                                                                         _recruitVacancyClient, locationEditModel, RouteNames.Location_Post);

            var accountLegalEntityPublicHashedId = !string.IsNullOrEmpty(employerInfoModel?.AccountLegalEntityPublicHashedId)
                ? employerInfoModel.AccountLegalEntityPublicHashedId : vacancy.AccountLegalEntityPublicHashedId;

            var employerVacancyInfoTask = _providerVacancyClient.GetProviderEmployerVacancyDataAsync(ukprn, vacancy.EmployerAccountId);
            var employerProfileTask     = _recruitVacancyClient.GetEmployerProfileAsync(vacancy.EmployerAccountId, accountLegalEntityPublicHashedId);
            await Task.WhenAll(employerProfileTask, employerVacancyInfoTask);

            var employerVacancyInfo  = employerVacancyInfoTask.Result;
            var employerProfile      = employerProfileTask.Result;
            var selectedOrganisation = employerVacancyInfo.LegalEntities.Single(l => l.AccountLegalEntityPublicHashedId == accountLegalEntityPublicHashedId);
            var allLocations         = await GetAllAvailableLocationsAsync(employerProfile, vacancy, ukprn);

            var newLocation =
                locationEditModel.SelectedLocation == LocationViewModel.UseOtherLocationConst
                    ? locationEditModel.ToAddressString()
                    : locationEditModel.SelectedLocation;

            var matchingAddress = GetMatchingAddress(newLocation, allLocations);

            var employerLocation = matchingAddress != null ? matchingAddress : ConvertToDomainAddress(locationEditModel);

            // this has diverged from the usual pattern because the individual properties are review fields
            SetVacancyWithProviderReviewFieldIndicators(
                vacancy.EmployerLocation?.AddressLine1,
                FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine1),
                vacancy,
                (v) =>
            {
                return(employerLocation.AddressLine1);
            });

            SetVacancyWithProviderReviewFieldIndicators(
                vacancy.EmployerLocation?.AddressLine2,
                FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine2),
                vacancy,
                (v) =>
            {
                return(employerLocation.AddressLine2);
            });

            SetVacancyWithProviderReviewFieldIndicators(
                vacancy.EmployerLocation?.AddressLine3,
                FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine3),
                vacancy,
                (v) =>
            {
                return(employerLocation.AddressLine3);
            });

            SetVacancyWithProviderReviewFieldIndicators(
                vacancy.EmployerLocation?.AddressLine4,
                FieldIdResolver.ToFieldId(v => v.EmployerLocation.AddressLine4),
                vacancy,
                (v) =>
            {
                return(employerLocation.AddressLine4);
            });

            SetVacancyWithProviderReviewFieldIndicators(
                vacancy.EmployerLocation?.Postcode,
                FieldIdResolver.ToFieldId(v => v.EmployerLocation.Postcode),
                vacancy,
                (v) =>
            {
                return(employerLocation.Postcode);
            });

            vacancy.EmployerLocation = employerLocation;

            // if cookie is found update legal entity and name option
            if (employerInfoModel != null)
            {
                SetVacancyWithProviderReviewFieldIndicators(
                    vacancy.LegalEntityName,
                    FieldIdResolver.ToFieldId(v => v.EmployerName),
                    vacancy,
                    (v) =>
                {
                    return(v.LegalEntityName = selectedOrganisation.Name);
                });

                SetVacancyWithProviderReviewFieldIndicators(
                    vacancy.EmployerNameOption,
                    FieldIdResolver.ToFieldId(v => v.EmployerName),
                    vacancy,
                    (v) =>
                {
                    return(v.EmployerNameOption = employerInfoModel.EmployerIdentityOption?.ConvertToDomainOption());
                });

                if (employerInfoModel.EmployerIdentityOption == EmployerIdentityOption.NewTradingName)
                {
                    SetVacancyWithProviderReviewFieldIndicators(
                        employerProfile.TradingName,
                        FieldIdResolver.ToFieldId(v => v.EmployerName),
                        vacancy,
                        (e) =>
                    {
                        // the indicator will be set for the vacancy when the employer profile will change to the new trading name
                        return(employerInfoModel.NewTradingName);
                    });
                }

                vacancy.AccountLegalEntityPublicHashedId = selectedOrganisation.AccountLegalEntityPublicHashedId;
                vacancy.AnonymousReason = vacancy.IsAnonymous ? employerInfoModel.AnonymousReason : null;
                vacancy.EmployerName    = vacancy.IsAnonymous ? employerInfoModel.AnonymousName : null;
            }

            return(await ValidateAndExecute(
                       vacancy,
                       v => _recruitVacancyClient.Validate(v, ValidationRules),
                       async v =>
            {
                await _recruitVacancyClient.UpdateDraftVacancyAsync(vacancy, user);
                await UpdateEmployerProfileAsync(employerInfoModel, employerProfile, matchingAddress == null ? vacancy.EmployerLocation : null, user);
            }));
        }