Beispiel #1
0
        ///<inheritdoc/>
        public static ICountryInfo GetCountryByNameConsiderTranslation(
            this ICountryProvider countryProvider,
            string countryName)
        {
            var countries = countryProvider.GetCountries();

            foreach (var country in countries)
            {
                if (country.CommonName.Equals(countryName, StringComparison.OrdinalIgnoreCase))
                {
                    return(country);
                }

                if (country.OfficialName.Equals(countryName, StringComparison.OrdinalIgnoreCase))
                {
                    return(country);
                }

                var translationProvider = new TranslationProvider();
                var countryTanslation   = translationProvider.GetCountryTranslation(country.Alpha2Code);
                if (countryTanslation.Translations.Any(translation => translation.Name.Equals(countryName, StringComparison.OrdinalIgnoreCase)))
                {
                    return(country);
                }
            }

            return(null);
        }
        public async Task <ImmutableList <CountryModel> > Handle(GetCountries request,
                                                                 CancellationToken cancellationToken)
        {
            var countries = await _countryProvider.GetCountries();

            return(countries.ToImmutableList());
        }
        public ActionResult Stub()
        {
            ViewBag.Title = "Stub";

            _provider = new CountryProvider(new CountryReaderStub());

            return View("CountryList", _provider.GetCountries());
        }
Beispiel #4
0
        public ActionResult Stub()
        {
            ViewBag.Title = "Stub";

            _provider = new CountryProvider(new CountryReaderStub());

            return(View("CountryList", _provider.GetCountries()));
        }
        public ActionResult XML()
        {
            ViewBag.Title = "XML";

            string strPath = HttpRuntime.BinDirectory + "\\Countries.xml";
            _provider = new CountryProvider(new CountryReader(strPath));

            return View("CountryList", _provider.GetCountries());
        }
Beispiel #6
0
        public ActionResult XML()
        {
            ViewBag.Title = "XML";

            string strPath = HttpRuntime.BinDirectory + "\\Countries.xml";

            _provider = new CountryProvider(new CountryReader(strPath));

            return(View("CountryList", _provider.GetCountries()));
        }
Beispiel #7
0
        public CountryMetadataProviderImpl(IServiceProvider serviceProvider, ILogger <CountryMetadataProviderImpl> logger)
        {
            _logger = logger;

            _countryProvider = new CountryProvider();

            var countries = _countryProvider.GetCountries();

            foreach (var country in countries)
            {
                var alpha2Code = country.Alpha2Code;

                var countryCode = Enum.GetName(typeof(Alpha2Code), alpha2Code).ToLower();

                var countryNameEn = _countryProvider.GetCountryTranslatedName(alpha2Code, LanguageCode.EN);

                if (string.IsNullOrEmpty(countryNameEn))
                {
                    throw new Exception($"Country name for {alpha2Code} is missing (EN)");
                }

                var countryNameDe = _countryProvider.GetCountryTranslatedName(alpha2Code, LanguageCode.DE);

                if (string.IsNullOrEmpty(countryNameDe))
                {
                    throw new Exception($"Country name for {alpha2Code} is missing (DE)");
                }

                _localizedCountryNameMappings["en"].Add(new CountryCodeNameMapping()
                {
                    CountryCode = countryCode,
                    Name        = countryNameEn
                });

                _localizedCountryNameMappings["de"].Add(new CountryCodeNameMapping()
                {
                    CountryCode = countryCode,
                    Name        = countryNameDe
                });

                _validCountryCodes.Add(countryCode);
            }

            _localizedCountryNameMappings["en"].Sort((country1, country2) =>
            {
                return(string.Compare(country1.Name, country2.Name));
            });

            _localizedCountryNameMappings["de"].Sort((country1, country2) =>
            {
                return(string.Compare(country1.Name, country2.Name));
            });

            _geoIP2DatabaseReader = serviceProvider.GetRequiredService <IGeoIP2DatabaseReader>();
        }
Beispiel #8
0
 public IObservable <List <ICountryEntity> > GetCountries()
 {
     return(Observable.Create <List <ICountryEntity> >(emitter =>
     {
         var countryEntities = countryProvider.GetCountries();
         emitter.OnNext(countryEntities);
         emitter.OnCompleted();
         return () => { };
     }).Do(countryList =>
     {
         countryCache.save(countryList);
     }));
 }
        public ActionResult Add(Country model)
        {
            if (ModelState.IsValid)
            {
                string strPath = HttpRuntime.BinDirectory + "\\Countries.xml";
                _provider = new CountryProvider(new CountryReader(strPath));

                List<Country> result = _provider.GetCountries().ToList();
                result.Add(model);

                if(_provider.SaveCountries(result))
                    return RedirectToAction("Index", "Country");
            }
            return View();
        }
Beispiel #10
0
        public ActionResult Add(Country model)
        {
            if (ModelState.IsValid)
            {
                string strPath = HttpRuntime.BinDirectory + "\\Countries.xml";
                _provider = new CountryProvider(new CountryReader(strPath));

                List <Country> result = _provider.GetCountries().ToList();
                result.Add(model);

                if (_provider.SaveCountries(result))
                {
                    return(RedirectToAction("Index", "Country"));
                }
            }
            return(View());
        }
        public async Task <ActionResult> GetCountries()
        {
            var countries = await _countryProvider.GetCountries();

            return(Json(countries, JsonRequestBehavior.AllowGet));
        }
Beispiel #12
0
 /// <summary>
 /// Constructor for <see cref="ChooseCountryWindowViewModel"/>.
 /// </summary>
 public ChooseCountryWindowViewModel(Action closeWindow, ICountryProvider countryProvider)
 {
     _closeWindow = closeWindow;
     AllCountries = countryProvider.GetCountries();
     AcceptChoose = new DelegateCommand(AcceptHandler, CanAcceptChoose);
 }