コード例 #1
0
        public static IEnumerable <SelectListItem> Countries(this HtmlHelper helper, IEnumerable <string> countryCodes, string defaultCountryCode = "US")
        {
            var apiCountries = ExigoDAL.GetCountries();
            var countries    = new List <Country>();
            var markets      = GlobalSettings.Markets.AvailableMarkets;

            // compare the countries in the Countries table for the company with the list of available markets in the Settings file
            foreach (var market in markets)
            {
                foreach (var country in market.Countries)
                {
                    var countryMatch = apiCountries.Where(c => c.CountryCode == country).FirstOrDefault();
                    if (countryMatch != null)
                    {
                        // ensure no duplicates are added
                        if (!countries.Any(c => c.CountryCode == countryMatch.CountryCode))
                        {
                            countries.Add(countryMatch);
                        }
                    }
                }
            }

            if (countryCodes != null && countryCodes.Count() > 0)
            {
                countries = countries.Where(c => countryCodes.Contains(c.CountryCode)).ToList();
            }

            return(countries.Select(c => new SelectListItem()
            {
                Text = c.CountryName,
                Value = c.CountryCode,
                Selected = c.CountryCode == defaultCountryCode
            }));
        }
コード例 #2
0
        public JsonNetResult GetCountries()
        {
            var countries = ExigoDAL.GetCountries();

            return(new JsonNetResult(new
            {
                success = true,
                countries = countries
            }));
        }
コード例 #3
0
        public static MvcHtmlString CountryOptions(this HtmlHelper helper, string defaultCountryCode = "US")
        {
            var response = ExigoDAL.GetCountries();

            var html = new StringBuilder();

            foreach (var country in response)
            {
                html.AppendFormat("<option value='{0}' {2}>{1}</option>"
                                  , country.CountryCode
                                  , country.CountryName
                                  , country.CountryCode.Equals(defaultCountryCode, StringComparison.InvariantCultureIgnoreCase) ? "selected" : "");
            }

            return(new MvcHtmlString(html.ToString()));
        }