Пример #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();
     }
 }
        private ReadModel.ApprenticeshipFavourites GenerateSingleWithNoLocation()
        {
            var newFavourites = new ReadModel.ApprenticeshipFavourites
            {
                new ReadModel.ApprenticeshipFavourite
                {
                    ApprenticeshipId = "123",
                    Title            = "Test Standard1",
                    Level            = 3,
                    TypicalLength    = 24,
                    Providers        = new List <ReadModel.Provider>
                    {
                        new ReadModel.Provider {
                            Name = "Test Provider", Ukprn = 10000020, Address = new Infrastructure.FatApiClient.ProviderAddress
                            {
                                Primary     = "1 Head Office",
                                Secondary   = "Training Provider",
                                Street      = "Training Provider Street",
                                Town        = "Training",
                                Postcode    = "AA1 1BB",
                                ContactType = "PRIMARY"
                            }, LocationIds = new List <int> {
                            },
                            Locations      = new List <Location> {
                            }
                        }
                    },
                }
            };

            return(newFavourites);
        }
        protected static ReadModel.ApprenticeshipFavourites GetTestRepositoryFavourites()
        {
            var list = new ReadModel.ApprenticeshipFavourites();

            list.Add(new ReadModel.ApprenticeshipFavourite("30", new Provider {
                Ukprn = 10000020, Name = "Test Provider Ltd", Phone = string.Empty, Email = string.Empty, Website = null, EmployerSatisfaction = 0, LearnerSatisfaction = 0
            })
            {
                Title = "Standard-30", Level = 4, TypicalLength = 24
            });
            list.Add(new ReadModel.ApprenticeshipFavourite("420-2-1")
            {
                Title = "Framework-420-2-1", Level = 3, TypicalLength = 18, ExpiryDate = new DateTime(2020, 1, 1)
            });
            list.Add(new ReadModel.ApprenticeshipFavourite("70", new Provider {
                Ukprn = 12345678
            })
            {
                Title = "Standard-70", Level = 5, TypicalLength = 12
            });
            list.Add(new ReadModel.ApprenticeshipFavourite("123", new Provider {
                Ukprn = 10000020, Name = "Test Provider Ltd", Phone = "020 123 1234", Email = "*****@*****.**", Website = new Uri("https://www.testprovider.com"), EmployerSatisfaction = 66, LearnerSatisfaction = 99
            })
            {
                Title = "Standard-123", Level = 2, TypicalLength = 24
            });
            list.Add(new ReadModel.ApprenticeshipFavourite("2", new Provider
            {
                Ukprn       = 10027893,
                Name        = "Test Provider Ltd",
                Address     = new ProviderAddress(),
                LocationIds = new List <int> {
                    155399
                },
                Locations = new List <Location> {
                    new Location
                    {
                        Address1   = "1 Test Address",
                        Address2   = "Location",
                        County     = "Location",
                        Town       = "City of Provider",
                        PostCode   = "AA1 2BB",
                        Name       = "Location Provider",
                        LocationId = 155399
                    }
                }
            })
            {
                Title = "Standard-70", Level = 5, TypicalLength = 12
            });

            return(list);
        }
Пример #5
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;
                }
            }
        }