public T New <T>() where T : new()
        {
            var model = new T();

            if (model is INeedCountries countryModel)
            {
                countryModel.Countries = referenceDataProvider.GetCountries();
            }

            if (model is INeedCounties countyModel)
            {
                countyModel.Counties = referenceDataProvider.GetCounties();
            }

            if (model is INeedStandards standardModel)
            {
                standardModel.Standards = statusRepository
                                          .GetAll <LicensingStandard>()
                                          .Select(s => new CheckboxListItem {
                    Id = s.Id, Name = s.Name
                })
                                          .ToList();
            }

            return(model);
        }
Esempio n. 2
0
        public SignUpViewModel Build(string email)
        {
            var model = new SignUpViewModel
            {
                Countries = referenceDataProvider.GetCountries(),
                Counties  = referenceDataProvider.GetCounties()
            };

            var user = userManager.FindCompleteUserByEmail(email);

            if (user != null)
            {
                model = mapper.Map(user, model);
            }

            return(model);
        }
Esempio n. 3
0
        public PublicRegisterLicenceListViewModel BuildSearchForLicences(
            PublicRegisterSearchCriteria publicRegisterSearchCriteria)
        {
            var ukCountryNames = UkCountries.Select(x => x.Text);

            var licences = _licenceRepository.GetAllLicencesForPublicRegister()
                           .Where(x => string.IsNullOrWhiteSpace(publicRegisterSearchCriteria.BusinessName) ||
                                  x.BusinessName.Contains(publicRegisterSearchCriteria.BusinessName));

            var countries = _referenceDataProvider.GetCountries();

            if (publicRegisterSearchCriteria.CountriesSelected != null && publicRegisterSearchCriteria.CountriesSelected.Count > 0)
            {
                switch (Enum.Parse <SupplierWho>(publicRegisterSearchCriteria.SupplierWho))
                {
                case SupplierWho.Supply:
                    if (publicRegisterSearchCriteria.CountriesSelected.Any(x => x == "UK"))
                    {
                        licences = licences.Where(x =>
                                                  ukCountryNames.Any(y => x.OperatingCountries.Any(z =>
                                                                                                   countries.Single(c => int.Parse(c.Value) == z.WorkerCountryId).Text == y)));
                    }
                    else if (publicRegisterSearchCriteria.CountriesSelected.Any(x => x == "Outside UK"))
                    {
                        licences = licences.Where(x =>
                                                  ukCountryNames.Any(y => x.OperatingCountries.All(z =>
                                                                                                   countries.Single(c => int.Parse(c.Value) == z.WorkerCountryId).Text != y)));
                    }
                    else
                    {
                        licences = licences.Where(x => x.OperatingCountries.Any(y => y != null &&
                                                                                publicRegisterSearchCriteria.CountriesSelected.Any(z =>
                                                                                                                                   countries.Single(c =>
                                                                                                                                                    int.Parse(c.Value) == y.WorkerCountryId).Text.Contains(z))));
                    }

                    break;

                case SupplierWho.AreLocated:
                    if (publicRegisterSearchCriteria.CountriesSelected.Any(x => x == "UK"))
                    {
                        licences = licences.Where(x =>
                                                  x.Address != null && ukCountryNames.Any(y =>
                                                                                          countries.Single(c => int.Parse(c.Value) == x.Address.CountryId).Text.Contains(y)));
                    }
                    else if (publicRegisterSearchCriteria.CountriesSelected.Any(x => x == "Outside UK"))
                    {
                        licences = licences.Where(x =>
                                                  x.Address != null && ukCountryNames.Any(y => !x.Address.Country.IsUk));
                    }
                    else
                    {
                        licences = licences.Where(x =>
                                                  x.Address != null &&
                                                  publicRegisterSearchCriteria.CountriesSelected.Any(y =>
                                                                                                     y == countries.Single(c => int.Parse(c.Value) == x.Address.CountryId).Text));
                    }

                    break;

                default:
                    throw new InvalidEnumArgumentException(nameof(publicRegisterSearchCriteria.SupplierWho));
                }
            }

            return(new PublicRegisterLicenceListViewModel
            {
                Licences = licences.Distinct().Select(BuildSummary),
                PublicRegisterSearchCriteria = publicRegisterSearchCriteria,
                AvailableCountries = BuildAvailableCountries(),
                Countries = countries,
                Counties = _referenceDataProvider.GetCounties()
            });
        }
Esempio n. 4
0
 private T RepopulateCounties <T>(T model) where T : INeedCounties
 {
     model.Counties = ReferenceDataProvider.GetCounties();
     return(model);
 }