コード例 #1
0
        public static IEnumerable <SelectListItem> Countries(this HtmlHelper helper, IEnumerable <string> countryCodes, string defaultCountryCode = "US")
        {
            var apiCountries = Exigo.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 = Exigo.GetCountries();

            return(new JsonNetResult(new
            {
                success = true,
                countries = countries
            }));
        }
コード例 #3
0
ファイル: Forms.cs プロジェクト: Webalap/W-ALAP
        public static IEnumerable <SelectListItem> Countries(this HtmlHelper helper, string defaultCountryCode = "US")
        {
            var response = Exigo.GetCountries();

            return(response.Select(c => new SelectListItem()
            {
                Text = c.CountryName,
                Value = c.CountryCode,
                Selected = c.CountryCode == defaultCountryCode
            }));
        }
コード例 #4
0
ファイル: Forms.cs プロジェクト: Webalap/W-ALAP
        public static MvcHtmlString CountryOptions(this HtmlHelper helper, string defaultCountryCode = "US")
        {
            var response = Exigo.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()));
        }
コード例 #5
0
        public static MvcHtmlString CountryOptions(this HtmlHelper helper, IEnumerable <string> countryCodes, string defaultCountryCode = "US")
        {
            var response = Exigo.GetCountries();

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

            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()));
        }
コード例 #6
0
        public static IEnumerable <SelectListItem> Countries(this HtmlHelper helper, IEnumerable <string> countryCodes, string defaultCountryCode = "US")
        {
            var countries = Exigo.GetCountries();

            if (countryCodes != null)
            {
                countries = countries.Where(c => c.CountryCode.In(countryCodes.ToArray())).ToList();
            }
            else
            {
                countries = countries.Where(c => c.CountryCode == defaultCountryCode).ToList();
            }
            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
            }));
        }
コード例 #7
0
        public static IEnumerable <SelectListItem> Countries(this HtmlHelper helper, IEnumerable <string> countryCodes, bool disableHT, int?CustomerID, string defaultCountryCode = "US")
        {
            var apiCountries = Exigo.GetCountries();
            var countries    = new List <Country>();

            //20170118 82825 DV. Reminder to self. Consider moving Field5 to the Identity object since it could be handy throughout entire project later.
            if (!disableHT)
            {
                using (var context = Exigo.Sql())
                {
                    var Field5 = context.Query <string>(@"
                                    SELECT Field5 FROM Customers WHERE CustomerID = @customerID
                                    ", new { CustomerID }).FirstOrDefault();

                    if (Field5.IsNotNullOrEmpty() && Field5 == "1") //That is, the value is likely a 1 for true. Most customers will have either an empty "" value or a value of 0 for Field5 if the CSR unchecks the Field5 user-defined field in Exigo Admin
                    {
                        Country US = new Country();
                        US.CountryCode = "US";
                        US.CountryName = "United States";
                        Country HT = new Country();
                        HT.CountryCode = "HT";
                        HT.CountryName = "Haiti";
                        countries.Add(US);
                        countries.Add(HT);

                        return(countries.Select(c => new SelectListItem()
                        {
                            Text = c.CountryName,
                            Value = c.CountryCode,
                            Selected = c.CountryCode == defaultCountryCode
                        }));
                    }
                }
            }

            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();

                    // 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
            }));
        }