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); }
public AdminStatusLicencesViewModel Build(int id) { return(new AdminStatusLicencesViewModel { LicenceApplicationViewModels = GetLicencesByStatus(id).ToList(), LicenceStatusViewModel = _mapper.Map <LicenceStatusViewModel>(_repository.GetById <LicenceStatus>(id)), Countries = _referenceDataProvider.GetCountries() }); }
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); }
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() }); }
private T RepopulateCountries <T>(T model) where T : INeedCountries { model.Countries = ReferenceDataProvider.GetCountries(); return(model); }