Пример #1
0
        private async Task EnrichFavourites(ReadModel.ApprenticeshipFavourites favourites)
        {
            if (favourites != null)
            {
                var apprenticeshipUpdateTasks = favourites.Select(UpdateApprenticeship).ToList();

                var providers = favourites.SelectMany(x => x.Providers)?.Select(y => y.Ukprn).Distinct();

                List <Task <FatTrainingProvider> > fatProviderTasks = null;

                List <Task <FatProviderLocationAddress> > fatGetLocationTasks = null;

                if (providers != null)
                {
                    fatProviderTasks = providers.Select(x => GetProviderDetails(x.ToString())).ToList();
                }

                var providerLocationsList = favourites.Where(w => w.Providers != null).SelectMany(a => a.Providers.Where(w => w.LocationIds != null), (a, p) => new { apprenticeshipId = a.ApprenticeshipId, isFramework = a.IsFramework, ukprn = p.Ukprn, locations = p.LocationIds });

                fatGetLocationTasks = providerLocationsList.SelectMany(l => l.locations.Select(s => GetProviderLocations(l.apprenticeshipId, l.isFramework, l.ukprn, s))).Select(x => x).ToList();

                await Task.WhenAll(apprenticeshipUpdateTasks.Concat(fatProviderTasks).Concat(fatGetLocationTasks));

                UpdateTrainingProviders(favourites, fatProviderTasks.Where(w => w.Result != null).Select(x => x.Result));

                UpdateLocations(favourites, fatGetLocationTasks.Where(w => w.Result != null).Select(y => y.Result).GroupBy(x => x.Location.LocationId).Select(g => g.First()));
            }
        }
Пример #2
0
 private void UpdateLocations(ReadModel.ApprenticeshipFavourites favourites, IEnumerable <FatProviderLocationAddress> locationData)
 {
     foreach (var provider in favourites.SelectMany(s => s.Providers).Where(w => w != null && w.LocationIds != null))
     {
         provider.Locations = locationData.Where(w => provider.LocationIds.Contains(w.Location.LocationId)).Select(UpdateLocation).ToList();
     }
 }
Пример #3
0
        private void UpdateTrainingProviders(ReadModel.ApprenticeshipFavourites favourites, IEnumerable <FatTrainingProvider> providerData)
        {
            foreach (var item in providerData)
            {
                var matchingProviders = favourites.SelectMany(x => x.Providers).Where(y => y.Ukprn == item.Ukprn);

                List <Location> locations = new List <Location>();

                foreach (var provider in matchingProviders)
                {
                    provider.Name    = item.ProviderName;
                    provider.Phone   = item.Phone;
                    provider.Email   = item.Email;
                    provider.Website = item.Website;
                    provider.EmployerSatisfaction = item.EmployerSatisfaction;
                    provider.LearnerSatisfaction  = item.LearnerSatisfaction;
                    provider.Address = item.Addresses.Find(x => x.ContactType == "PRIMARY");
                    provider.Active  = true;
                }
            }
        }