public async Task <GetTrainingCourseResult> Handle(GetTrainingCourseQuery request, CancellationToken cancellationToken) { var location = await _locationLookupService.GetLocationInformation(request.LocationName, request.Lat, request.Lon); var standardTask = _apiClient.Get <GetStandardsListItem>(new GetStandardRequest(request.Id)); var providersTask = _courseDeliveryApiClient.Get <GetUkprnsForStandardAndLocationResponse>(new GetUkprnsForStandardAndLocationRequest(request.Id, location?.GeoPoint?.First() ?? 0, location?.GeoPoint?.Last() ?? 0)); var levelsTask = _cacheHelper.GetRequest <GetLevelsListResponse>(_apiClient, new GetLevelsListRequest(), nameof(GetLevelsListResponse), out _); var shortlistTask = _shortlistService.GetShortlistItemCount(request.ShortlistUserId); await Task.WhenAll(standardTask, providersTask, levelsTask, shortlistTask); if (standardTask.Result == null) { return(new GetTrainingCourseResult()); } standardTask.Result.LevelEquivalent = levelsTask.Result.Levels.SingleOrDefault(x => x.Code == standardTask.Result.Level)?.Name; return(new GetTrainingCourseResult { Course = standardTask.Result, ProvidersCount = providersTask.Result.UkprnsByStandard.ToList().Count, ProvidersCountAtLocation = providersTask.Result.UkprnsByStandardAndLocation.ToList().Count, ShortlistItemCount = shortlistTask.Result }); }
public async Task <GetTrainingCourseProvidersResult> Handle(GetTrainingCourseProvidersQuery request, CancellationToken cancellationToken) { var locationTask = _locationLookupService.GetLocationInformation(request.Location, request.Lat, request.Lon); var courseTask = _coursesApiClient.Get <GetStandardsListItem>(new GetStandardRequest(request.Id)); var shortlistTask = _shortlistService.GetShortlistItemCount(request.ShortlistUserId); await Task.WhenAll(locationTask, courseTask, shortlistTask); var showEmployerDemand = _config.EmployerDemandFeatureToggle && await _employerDemandApiClient.GetResponseCode(new GetShowEmployerDemandRequest()) == HttpStatusCode.OK; var providers = await _courseDeliveryApiClient.Get <GetProvidersListResponse>(new GetProvidersByCourseRequest( request.Id, courseTask.Result.SectorSubjectAreaTier2Description, courseTask.Result.Level, locationTask.Result?.GeoPoint?.FirstOrDefault(), locationTask.Result?.GeoPoint?.LastOrDefault(), request.SortOrder, request.ShortlistUserId)); return(new GetTrainingCourseProvidersResult { Course = courseTask.Result, Providers = providers.Providers, Total = providers.TotalResults, Location = locationTask.Result, ShortlistItemCount = shortlistTask.Result, ShowEmployerDemand = showEmployerDemand }); }
public async Task <GetEmployerCourseProviderDemandQueryResult> Handle(GetEmployerCourseProviderDemandQuery request, CancellationToken cancellationToken) { var courseTask = _coursesApiClient.Get <GetStandardsListItem>(new GetStandardRequest(request.CourseId)); var locationTask = _locationLookupService.GetLocationInformation(request.LocationName, 0, 0, true); var providerCourseInfoTask = _courseDeliveryApiClient.Get <GetProviderCourseInformation>( new GetProviderCourseInformationRequest(request.Ukprn, request.CourseId)); await Task.WhenAll(courseTask, locationTask, providerCourseInfoTask); var radius = locationTask.Result != null ? request.LocationRadius : null; var demand = await _employerDemandApiClient.Get <GetEmployerCourseProviderListResponse>( new GetCourseProviderDemandsRequest(request.Ukprn, request.CourseId, locationTask.Result?.GeoPoint?.FirstOrDefault(), locationTask.Result?.GeoPoint?.LastOrDefault(), radius)); return(new GetEmployerCourseProviderDemandQueryResult { Course = courseTask.Result, Location = locationTask.Result, EmployerCourseDemands = demand.EmployerCourseDemands, Total = demand.Total, TotalFiltered = demand.TotalFiltered, ProviderDetail = providerCourseInfoTask.Result }); }
public async Task <GetAdvertsQueryResult> Handle(GetAdvertsQuery request, CancellationToken cancellationToken) { var routesTask = _courseService.GetRoutes(); var standardsTask = _courseService.GetActiveStandards <GetStandardsListResponse>(nameof(GetStandardsListResponse)); var locationTask = _locationLookupService.GetLocationInformation(request.Postcode, 0, 0); await Task.WhenAll(routesTask, locationTask, standardsTask); if (locationTask.Result == null) { return(new GetAdvertsQueryResult { Routes = routesTask.Result.Routes, Vacancies = new List <GetVacanciesListItem>() }); } var standardLarsCode = standardsTask.Result.Standards.Where(c => c.Route.Equals(request.Route, StringComparison.CurrentCultureIgnoreCase)).Select(c => c.LarsCode).ToList(); var apprenticeshipVacancies = new List <GetVacanciesListItem>(); var skip = 0; var take = 15; while (true) { var standards = standardLarsCode.Skip(skip).Take(take).ToList(); if (standards.Count == 0) { break; } var advertRequest = new GetVacanciesRequest(0, 20, null, null, null, standards, null, locationTask.Result.GeoPoint.FirstOrDefault(), locationTask.Result.GeoPoint.LastOrDefault(), request.Distance, null, null, "DistanceAsc"); var adverts = await _findApprenticeshipApiClient.Get <GetVacanciesResponse>(advertRequest); apprenticeshipVacancies.AddRange(adverts.ApprenticeshipVacancies.ToList()); skip += take; } foreach (var advert in apprenticeshipVacancies) { advert.VacancyUrl = $"{_configuration.FindAnApprenticeshipBaseUrl}/apprenticeship/reference/{advert.VacancyReference}"; } return(new GetAdvertsQueryResult { Location = locationTask.Result, Routes = routesTask.Result.Routes, TotalFound = apprenticeshipVacancies.Count, Vacancies = apprenticeshipVacancies.OrderBy(c => c.Distance).Take(20) }); }
public async Task <GetGeoPointQueryResult> Handle(GetGeoPointQuery request, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(request.Postcode)) { throw new ArgumentException($"Postcode is required", nameof(GetGeoPointQuery.Postcode)); } var location = await _locationLookupService.GetLocationInformation(request.Postcode, default, default);
public async Task <GetLocationInformationResult> Handle(GetLocationInformationQuery request, CancellationToken cancellationToken) { var result = await _locationLookupService.GetLocationInformation(request.Location, request.Latitude, request.Longitude); return(result == null ? new GetLocationInformationResult() : new GetLocationInformationResult { Name = result.Name, GeoPoint = result.GeoPoint }); }
public async Task <GetRegisterDemandResult> Handle(GetRegisterDemandQuery request, CancellationToken cancellationToken) { var course = _coursesApiClient.Get <GetStandardsListItem>(new GetStandardRequest(request.CourseId)); var location = _locationLookupService.GetLocationInformation(request.LocationName, 0, 0); await Task.WhenAll(course, location); return(new GetRegisterDemandResult { Course = course.Result, Location = location.Result }); }
public async Task <GetTrainingCourseProvidersResult> Handle(GetTrainingCourseProvidersQuery request, CancellationToken cancellationToken) { var locationTask = _locationLookupService.GetLocationInformation(request.Location, request.Lat, request.Lon); var courseTask = _coursesApiClient.Get <GetStandardsListItem>(new GetStandardRequest(request.Id)); var shortlistTask = _shortlistService.GetShortlistItemCount(request.ShortlistUserId); await Task.WhenAll(locationTask, courseTask, shortlistTask); var providers = await _courseDeliveryApiClient.Get <GetProvidersListResponse>(new GetProvidersByCourseRequest( request.Id, courseTask.Result.SectorSubjectAreaTier2Description, courseTask.Result.Level, locationTask.Result?.GeoPoint?.FirstOrDefault(), locationTask.Result?.GeoPoint?.LastOrDefault(), request.SortOrder, request.ShortlistUserId)); if (providers?.Providers.Any() == true) { var ukprns = providers.Providers.Select(s => s.Ukprn); var apprenticeFeedbackRatings = await _apprenticeFeedbackApiClient. PostWithResponseCode <IEnumerable <GetApprenticeFeedbackResponse> >( new PostApprenticeFeedbackRequest { Data = new PostApprenticeFeedbackRequestData { Ukprns = ukprns } }); if (apprenticeFeedbackRatings.StatusCode == HttpStatusCode.OK) { foreach (var ratingResponse in apprenticeFeedbackRatings.Body) { providers.Providers.First(s => s.Ukprn == ratingResponse.Ukprn).ApprenticeFeedback = ratingResponse; } } } return(new GetTrainingCourseProvidersResult { Course = courseTask.Result, Providers = providers?.Providers, Total = providers?.TotalResults ?? 0, Location = locationTask.Result, ShortlistItemCount = shortlistTask.Result }); }
public async Task <CreatePledgeResult> Handle(CreatePledgeCommand request, CancellationToken cancellationToken) { _logger.LogInformation($"Creating Pledge for account {request.AccountId}"); var account = await _levyTransferMatchingService.GetAccount(new GetAccountRequest(request.AccountId)); if (account == null) { _logger.LogInformation($"Account {request.AccountId} does not exist - creating"); await _levyTransferMatchingService.CreateAccount(new CreateAccountRequest(request.AccountId, request.DasAccountName)); } var locationDataItems = new List <LocationDataItem>(); foreach (var location in request.Locations) { var locationInformationResult = await _locationLookupService.GetLocationInformation(location, 0, 0); locationDataItems.Add(new LocationDataItem { Name = locationInformationResult.Name, GeoPoint = locationInformationResult.GeoPoint }); } var apiRequest = new CreatePledgeRequest(request.AccountId, new CreatePledgeRequest.CreatePledgeRequestData { AccountId = request.AccountId, Amount = request.Amount, IsNamePublic = request.IsNamePublic, DasAccountName = request.DasAccountName, Sectors = request.Sectors, JobRoles = request.JobRoles, Levels = request.Levels, Locations = locationDataItems, UserId = request.UserId, UserDisplayName = request.UserDisplayName }); var result = await _levyTransferMatchingService.CreatePledge(apiRequest); return(new CreatePledgeResult { PledgeId = result.Id, }); }
public async Task <GetTrainingCourseProviderResult> Handle(GetTrainingCourseProviderQuery request, CancellationToken cancellationToken) { var locationTask = _locationLookupService.GetLocationInformation(request.Location, request.Lat, request.Lon); var courseTask = _coursesApiClient.Get <GetStandardsListItem>(new GetStandardRequest(request.CourseId)); await Task.WhenAll(locationTask, courseTask); var ukprnsCount = _courseDeliveryApiClient.Get <GetUkprnsForStandardAndLocationResponse>( new GetUkprnsForStandardAndLocationRequest(request.CourseId, locationTask.Result?.GeoPoint?.FirstOrDefault() ?? 0, locationTask.Result?.GeoPoint?.LastOrDefault() ?? 0)); var providerTask = _courseDeliveryApiClient.Get <GetProviderStandardItem>( new GetProviderByCourseAndUkPrnRequest(request.ProviderId, request.CourseId, courseTask.Result.SectorSubjectAreaTier2Description, locationTask.Result?.GeoPoint?.FirstOrDefault(), locationTask.Result?.GeoPoint?.LastOrDefault(), request.ShortlistUserId)); var providerCoursesTask = _courseDeliveryApiClient.Get <GetProviderAdditionalStandardsItem>( new GetProviderAdditionalStandardsRequest(request.ProviderId)); var overallAchievementRatesTask = _courseDeliveryApiClient.Get <GetOverallAchievementRateResponse>( new GetOverallAchievementRateRequest(courseTask.Result.SectorSubjectAreaTier2Description)); var coursesTask = _cacheHelper.GetRequest <GetStandardsListResponse>(_coursesApiClient, new GetAvailableToStartStandardsListRequest(), nameof(GetStandardsListResponse), out var saveToCache); var shortlistTask = _shortlistService.GetShortlistItemCount(request.ShortlistUserId); await Task.WhenAll(providerTask, coursesTask, providerCoursesTask, ukprnsCount, overallAchievementRatesTask, shortlistTask); if (providerTask.Result == null && locationTask.Result != null) { providerTask = Task.FromResult( await _courseDeliveryApiClient.Get <GetProviderStandardItem>( new GetProviderByCourseAndUkPrnRequest(request.ProviderId, request.CourseId, courseTask.Result.SectorSubjectAreaTier2Description, null, null, request.ShortlistUserId))); if (providerTask.Result != null) { providerTask.Result.DeliveryTypes = new List <GetDeliveryTypeItem> { new GetDeliveryTypeItem { DeliveryModes = "NotFound" } }; } } await _cacheHelper.UpdateCachedItems(null, null, coursesTask, new CacheHelper.SaveToCache { Levels = false, Sectors = false, Standards = saveToCache }); var additionalCourses = providerCoursesTask.Result.StandardIds.Any() ? BuildAdditionalCoursesResponse(request, providerCoursesTask, coursesTask) : new List <GetAdditionalCourseListItem>(); return(new GetTrainingCourseProviderResult { ProviderStandard = providerTask.Result, Course = courseTask.Result, AdditionalCourses = additionalCourses, OverallAchievementRates = overallAchievementRatesTask.Result.OverallAchievementRates, TotalProviders = ukprnsCount.Result.UkprnsByStandard.Count(), TotalProvidersAtLocation = ukprnsCount.Result.UkprnsByStandardAndLocation.Count(), Location = locationTask.Result, ShortlistItemCount = shortlistTask.Result }); }
public async Task <GetAggregatedCourseDemandListResult> Handle(GetAggregatedCourseDemandListQuery request, CancellationToken cancellationToken) { var locationTask = _locationLookupService.GetLocationInformation(request.LocationName, default, default);