Exemple #1
0
        public static Language GetLanguageByCustomerID(int customerID)
        {
            var defaultCultureCode = GlobalSettings.Markets.AvailableMarkets.FirstOrDefault(c => c.IsDefault).CultureCode;
            var defaultLanguage    = Exigo.GetLanguages().FirstOrDefault(c => c.CultureCode == defaultCultureCode).LanguageID;

            var languageID = defaultLanguage;

            // Get the user's language preference based on their saved preference
            if (HttpContext.Current.Request.IsAuthenticated)
            {
                using (var sqlContext = Exigo.Sql())
                {
                    languageID = sqlContext.Query <int>(@"select top 1 LanguageID from Customers where CustomerID = @customerID", new { customerID = customerID }).FirstOrDefault();
                }
            }

            var language = Exigo.GetLanguageByID(languageID);

            // If we couldn't find the user's preferred language, return the first one we find.
            if (language == null)
            {
                language = Exigo.GetLanguages().FirstOrDefault();
            }

            // Return the language
            return(language);
        }
Exemple #2
0
        public static string GetSelectedLanguage()
        {
            var defaultLanguage = GlobalSettings.Markets.AvailableMarkets.Where(c => c.IsDefault).FirstOrDefault().CultureCode;
            var languageCookie  = HttpContext.Current.Request.Cookies[GlobalSettings.Globalization.LanguageCookieName];

            if (languageCookie == null)
            {
                languageCookie          = new HttpCookie(GlobalSettings.Globalization.LanguageCookieName);
                languageCookie.Value    = defaultLanguage;
                languageCookie.HttpOnly = false;
                HttpContext.Current.Response.Cookies.Add(languageCookie);
            }

            var language = Exigo.GetLanguages().FirstOrDefault(c => c.CultureCode == languageCookie.Value);

            if (language == null)
            {
                languageCookie.Value = defaultLanguage;
            }


            return(languageCookie.Value);
        }