Esempio n. 1
0
        public ActionResult LanguagePicker(LanguagePickerFormData languagePickerFormData)
        {
            if (!String.IsNullOrEmpty(languagePickerFormData.SelectedLanguage))
            {
                string language = languagePickerFormData.SelectedLanguage.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[0];
                string culture = languagePickerFormData.SelectedLanguage.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries)[1];
                AtomiaCultureInfo atomiaLanguages = new AtomiaCultureInfo { Language = language, Culture = culture };
                this.HttpContext.Session["SessionAccountLanguages"] = atomiaLanguages;

                try
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();

                    AtomiaCookieCollection cookieCollection;
                    if (this.Request.Cookies["AtomiaCookieCollection"] != null && !String.IsNullOrEmpty(this.Request.Cookies["AtomiaCookieCollection"].Value))
                    {
                        cookieCollection = js.Deserialize<AtomiaCookieCollection>(this.Request.Cookies["AtomiaCookieCollection"].Value);
                    }
                    else
                    {
                        cookieCollection = new AtomiaCookieCollection();
                    }

                    AtomiaCookie aCookie = new AtomiaCookie(
                        this.Request.ApplicationPath,
                        this.Request.Url.Host,
                        js.Serialize(atomiaLanguages),
                        "OrderLanguageCookie");

                    cookieCollection.AddOrUpdateAtomiaCookie(aCookie);

                    string serializedCookieCollection = js.Serialize(cookieCollection);

                    HttpCookie cookie = new HttpCookie("AtomiaCookieCollection") { Value = serializedCookieCollection, Expires = DateTime.Now.AddYears(1) };

                    if (this.Request.Cookies["AtomiaCookieCollection"] != null && !String.IsNullOrEmpty(this.Request.Cookies["AtomiaCookieCollection"].Value))
                    {
                        this.Response.Cookies["AtomiaCookieCollection"].Value = cookie.Value;
                        this.Response.Cookies["AtomiaCookieCollection"].Expires = cookie.Expires;
                    }
                    else
                    {
                        this.Response.Cookies.Add(cookie);
                    }

                    try
                    {
                        var service = GeneralHelper.GetPublicOrderService(this.HttpContext.ApplicationInstance.Context);
                        string orderCurrencyResource = LocalizationHelpers.GlobalResource(String.Format("{0}Common, Currency" + languagePickerFormData.SelectedLanguage, this.HttpContext.Session["Theme"]))
                                                        ?? LocalizationHelpers.GlobalResource(String.Format("{0}Common, Currency", this.HttpContext.Session["Theme"]));
                        this.HttpContext.Session["OrderCurrencyResource"] = orderCurrencyResource;
                        string orderCurrencyCode = "SEK";

                        if (this.HttpContext.Application["CurrencyCode" + languagePickerFormData.SelectedLanguage] != null &&
                            !String.IsNullOrEmpty(
                                (string)this.HttpContext.Application["CurrencyCode" + languagePickerFormData.SelectedLanguage]))
                        {
                            orderCurrencyCode =
                                (string)this.HttpContext.Application["CurrencyCode" + languagePickerFormData.SelectedLanguage];
                        }

                        this.HttpContext.Session["OrderCurrencyCode"] = orderCurrencyCode;
                        Guid resellerId = ResellerHelper.GetResellerId();

                        Plugin.DomainSearch.Helpers.DomainSearchHelper.LoadProductsIntoSession(service, Guid.Empty, resellerId, orderCurrencyCode, culture);
                    }
                    catch (Exception ex)
                    {
                        OrderPageLogger.LogOrderPageException(ex);
                    }

                }
                catch (Exception ex)
                {
                    OrderPageLogger.LogOrderPageException(ex);
                    throw;
                }
            }

            // remove lang parameter when using language form
            string returnUrl = this.FilterReturnUrl(languagePickerFormData.ReturnUrl);
            this.Response.Redirect(returnUrl);

            // View does not exist, but redirect wont pass if some View is not called. :/
            return this.View("Index");
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the cookie.
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        /// <param name="languageObj">The language obj.</param>
        private void UpdateCookie(ActionExecutingContext filterContext, AtomiaCultureInfo languageObj)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();

            AtomiaCookieCollection cookieCollection;
            if (filterContext.HttpContext.Request.Cookies["AtomiaCookieCollection"] != null
                && !String.IsNullOrEmpty(filterContext.HttpContext.Request.Cookies["AtomiaCookieCollection"].Value))
            {
                cookieCollection = js.Deserialize<AtomiaCookieCollection>(filterContext.HttpContext.Request.Cookies["AtomiaCookieCollection"].Value);
            }
            else
            {
                cookieCollection = new AtomiaCookieCollection();
            }

            AtomiaCookie aCookie = new AtomiaCookie(
                filterContext.HttpContext.Request.ApplicationPath,
                filterContext.HttpContext.Request.Url.Host,
                js.Serialize(languageObj),
                "OrderLanguageCookie");

            cookieCollection.AddOrUpdateAtomiaCookie(aCookie);

            string serializedCookieCollection = js.Serialize(cookieCollection);

            HttpCookie cookie = new HttpCookie("AtomiaCookieCollection") { Value = serializedCookieCollection, Expires = DateTime.Now.AddYears(1) };

            if (filterContext.HttpContext.Request.Cookies["AtomiaCookieCollection"] != null && !String.IsNullOrEmpty(filterContext.HttpContext.Request.Cookies["AtomiaCookieCollection"].Value))
            {
                filterContext.HttpContext.Response.Cookies["AtomiaCookieCollection"].Value = cookie.Value;
                filterContext.HttpContext.Response.Cookies["AtomiaCookieCollection"].Expires = cookie.Expires;
            }
            else
            {
                filterContext.HttpContext.Response.Cookies.Add(cookie);
            }
        }
Esempio n. 3
0
        public ActionResult LocalePicker(LocalePickerFormData localePickerFormData)
        {
            if (!String.IsNullOrEmpty(localePickerFormData.SelectedCountry))
            {
                try
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();

                    AtomiaCookieCollection cookieCollection;
                    if (this.Request.Cookies["AtomiaCookieCollection"] != null && !String.IsNullOrEmpty(this.Request.Cookies["AtomiaCookieCollection"].Value))
                    {
                        cookieCollection = js.Deserialize<AtomiaCookieCollection>(this.Request.Cookies["AtomiaCookieCollection"].Value);
                    }
                    else
                    {
                        cookieCollection = new AtomiaCookieCollection();
                    }

                    AtomiaCookie aCookie = new AtomiaCookie(
                        this.Request.ApplicationPath,
                        this.Request.Url.Host,
                        localePickerFormData.SelectedCountry,
                        "OrderLocaleCookie");

                    cookieCollection.AddOrUpdateAtomiaCookie(aCookie);

                    string serializedCookieCollection = js.Serialize(cookieCollection);

                    HttpCookie cookie = new HttpCookie("AtomiaCookieCollection") { Value = serializedCookieCollection, Expires = DateTime.Now.AddYears(1) };

                    if (this.Request.Cookies["AtomiaCookieCollection"] != null && !String.IsNullOrEmpty(this.Request.Cookies["AtomiaCookieCollection"].Value))
                    {
                        this.Response.Cookies["AtomiaCookieCollection"].Value = cookie.Value;
                        this.Response.Cookies["AtomiaCookieCollection"].Expires = cookie.Expires;
                    }
                    else
                    {
                        this.Response.Cookies.Add(cookie);
                    }
                }
                catch (Exception ex)
                {
                    OrderPageLogger.LogOrderPageException(ex);
                    throw;
                }
            }

            this.Response.Redirect(localePickerFormData.ReturnUrl);

            // View does not exist, but redirect wont pass if some View is not called. :/
            return this.View("Index");
        }