コード例 #1
0
        public IActionResult Country(string countrycode, int year = 0)
        {
            if (year == 0)
            {
                year = DateTime.Now.Year;
            }

            if (!Enum.TryParse(countrycode, true, out CountryCode countryCode))
            {
                return(NotFound());
            }

            var country = new Country.CountryProvider().GetCountry(countryCode.ToString());

            var item = new PublicHolidayInfo
            {
                Country     = country.CommonName,
                CountryCode = countrycode,
                Year        = year
            };

            return(View(item));

            //if (item.PublicHolidays.Count > 0)
            //{
            //
            //}

            //return LocalRedirect("/");
        }
コード例 #2
0
        public ActionResult <CountryInfoDto> CountryInfo([FromQuery] string countryCode = null)
        {
            if (string.IsNullOrEmpty(countryCode))
            {
                countryCode = this.AutoDetectCountryCode();
            }

            var country = new Country.CountryProvider().GetCountry(countryCode);

            if (country == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            var countryInfo = new CountryInfoDto
            {
                CommonName           = country.CommonName,
                OfficialName         = country.OfficialName,
                CountryCode          = countryCode,
                AlternativeSpellings = country.Translations.Select(o => o.Name).ToArray(),
                Region  = country.Region.ToString(),
                Borders = this.GetCountryInfos(country.BorderCountrys)
            };

            return(StatusCode(StatusCodes.Status200OK, countryInfo));
        }
コード例 #3
0
        private string GetName(CountryCode countrycode)
        {
            var country = new Country.CountryProvider().GetCountry(countrycode.ToString());

            if (country == null)
            {
                return(string.Empty);
            }

            return(country.CommonName);
        }
コード例 #4
0
        public ActionResult <CountryInfoDto> CountryInfo([FromQuery] string countryCode = null)
        {
            #region Auto detect country

            if (string.IsNullOrEmpty(countryCode))
            {
                try
                {
                    var acceptLanguages = HttpContext.Request.GetTypedHeaders().AcceptLanguage;
                    var firstLanguage   = acceptLanguages.FirstOrDefault().ToString();

                    var cultureInfo = CultureInfo.GetCultureInfo(firstLanguage);
                    if (cultureInfo.IsNeutralCulture)
                    {
                        var region = new RegionInfo(firstLanguage);
                        countryCode = region.TwoLetterISORegionName;
                    }
                    else
                    {
                        var region = new RegionInfo(cultureInfo.CompareInfo.LCID);
                        countryCode = region.TwoLetterISORegionName;
                    }
                }
                catch
                {
                    //Fallback
                    countryCode = "US";
                }
            }

            #endregion

            var country = new Country.CountryProvider().GetCountry(countryCode);
            if (country == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            var countryInfo = new CountryInfoDto
            {
                CommonName           = country.CommonName,
                OfficialName         = country.OfficialName,
                CountryCode          = countryCode,
                AlternativeSpellings = country.Translations.Select(o => o.Name).ToArray(),
                Region  = country.Region.ToString(),
                Borders = this.GetCountryInfos(country.BorderCountrys)
            };

            return(StatusCode(StatusCodes.Status200OK, countryInfo));
        }
コード例 #5
0
        public ActionResult <CountryInfoDto> CountryInfo(
            [FromRoute][Required] string countryCode = null)
        {
            var country = new Country.CountryProvider().GetCountry(countryCode);

            if (country == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }

            var countryInfo = CountryHelper.Convert(country);

            return(this.StatusCode(StatusCodes.Status200OK, countryInfo));
        }
コード例 #6
0
        public ActionResult <CountryInfoDto> CountryInfo([FromQuery] string countryCode = null)
        {
            if (string.IsNullOrEmpty(countryCode))
            {
                countryCode = this.AutoDetectCountryCode();
            }

            var country = new Country.CountryProvider().GetCountry(countryCode);

            if (country == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }

            var countryInfo = CountryHelper.Convert(country);

            return(StatusCode(StatusCodes.Status200OK, countryInfo));
        }
コード例 #7
0
        private static CountryInfoDto[] GetBorderCountryInfos(Alpha2Code[] countryCodes)
        {
            var countryProvider = new Country.CountryProvider();
            var items           = new List <CountryInfoDto>();

            foreach (var countryCode in countryCodes)
            {
                var country = countryProvider.GetCountry(countryCode);

                var countryInfo = new CountryInfoDto
                {
                    CommonName   = country.CommonName,
                    OfficialName = country.OfficialName,
                    CountryCode  = country.Alpha2Code.ToString(),
                    Region       = country.Region.ToString()
                };

                items.Add(countryInfo);
            }

            return(items.ToArray());
        }
コード例 #8
0
        private CountryInfoDto[] GetCountryInfos(Country.Alpha2Code[] countryCodes)
        {
            var countryProvider = new Country.CountryProvider();
            var items           = new List <CountryInfoDto>();

            foreach (var countryCode in countryCodes)
            {
                var country = countryProvider.GetCountry(countryCode);

                var countryInfo = new CountryInfoDto
                {
                    CommonName           = country.CommonName,
                    OfficialName         = country.OfficialName,
                    CountryCode          = country.Alpha2Code.ToString(),
                    AlternativeSpellings = country.Translations.Select(o => o.Name).ToArray(),
                    Region = country.Region.ToString()
                };

                items.Add(countryInfo);
            }

            return(items.ToArray());
        }
コード例 #9
0
        private string GetName(CountryCode countryCode)
        {
            var country = new Country.CountryProvider().GetCountry(countryCode.ToString());

            return(country?.CommonName);
        }