Example #1
0
        public ActionResult LocalSettings(LocalSettings item)
        {
            item.Store       = Store.TryFind(item.StoreId);
            item.PointOfSale = PointOfSale.TryFind(item.PointOfSaleId);
            item.CashDrawer  = CashDrawer.TryFind(item.CashDrawerId.GetValueOrDefault());

            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            Response.Cookies.Add(new HttpCookie(WebConfig.StoreCookieKey)
            {
                Value   = item.Store.Id.ToString(),
                Expires = DateTime.Now.AddYears(100)
            });

            if (item.PointOfSale != null)
            {
                Response.Cookies.Add(new HttpCookie(WebConfig.PointOfSaleCookieKey)
                {
                    Value   = item.PointOfSale.Id.ToString(),
                    Expires = DateTime.Now.AddYears(100)
                });
            }
            else
            {
                if (Request.Cookies [WebConfig.PointOfSaleCookieKey] != null)
                {
                    Response.Cookies.Add(new HttpCookie(WebConfig.PointOfSaleCookieKey)
                    {
                        Value   = string.Empty,
                        Expires = DateTime.Now.AddDays(-1d)
                    });
                }
            }

            if (item.CashDrawer != null)
            {
                Response.Cookies.Add(new HttpCookie(WebConfig.CashDrawerCookieKey)
                {
                    Value   = item.CashDrawer.Id.ToString(),
                    Expires = DateTime.Now.AddYears(100)
                });
            }
            else
            {
                if (Request.Cookies [WebConfig.CashDrawerCookieKey] != null)
                {
                    Response.Cookies.Add(new HttpCookie(WebConfig.CashDrawerCookieKey)
                    {
                        Value   = string.Empty,
                        Expires = DateTime.Now.AddDays(-1d)
                    });
                }
            }

            return(RedirectToAction("Index", "Home"));
        }