コード例 #1
0
ファイル: SessionUtils.cs プロジェクト: chrisjigander/FMC
        internal static void EditProduct(OrderController orderController, string artNr, string size, int plusOrMinus, WebShopDBContext context)
        {
            string[] articlesInCart = GetArticleNumbersInCart(orderController);
            string   article        = articlesInCart.First(a => a.StartsWith($"{artNr}{size}"));

            string[] articleSplit = article.Split(';');
            int      sessionKey   = GetSessionIndex(orderController, articleSplit[0]);

            if (articleSplit[1] == "1" && plusOrMinus == 1)
            {
                int totalRows = Convert.ToInt32(GetSingleSessionCount(orderController));
                orderController.HttpContext.Session.Remove(sessionKey.ToString());
                UpdateCartSessions(orderController, sessionKey, totalRows);
            }
            else
            {
                int count = Convert.ToInt32(articleSplit[1]);
                if (plusOrMinus == 1) // Ta bort EN produkt
                {
                    count--;
                }
                else if (plusOrMinus == 2 && (context.CheckIfInStock(sessionKey.ToString(), orderController))) // Lägg till EN produkt
                {
                    count++;
                }

                string newArticleString = $"{articleSplit[0]};{count.ToString()}";
                orderController.HttpContext.Session.SetString(sessionKey.ToString(), newArticleString);
            }
        }
コード例 #2
0
ファイル: DataManager.cs プロジェクト: chrisjigander/FMC
        public static void AddToCart(ProductController controller, ProductProductItemVM prodItemVM, WebShopDBContext webShopDBContext)
        {
            string index = "-1";

            for (int i = 0; i < 20; i++)
            {
                if (controller.HttpContext.Session.GetString(i.ToString()) == null)
                {
                    index = i.ToString();
                    break;
                }
            }

            string size  = webShopDBContext.Size.First(s => s.SizeId == Convert.ToInt32(prodItemVM.SelectedSize)).SizeName;
            string artNr = $"{prodItemVM.ArticleNum}{size}";

            int indexOfArticle = SessionUtils.GetSessionIndex(controller, artNr);

            bool isInStock = webShopDBContext.CheckIfInStock(indexOfArticle.ToString(), controller);

            if (isInStock)
            {
                if (index == "-1")
                {
                }
                else
                {
                    int numberOfSame = SessionUtils.GetSessionIndex(controller, artNr);

                    if (numberOfSame == -1)
                    {
                        string sessionString = $"{artNr};1";
                        controller.HttpContext.Session.SetString(index, sessionString);
                    }
                    else
                    {
                        string[] splitt         = controller.HttpContext.Session.GetString(numberOfSame.ToString()).Split(';');
                        int      numberOfArt    = Convert.ToInt32(splitt[1]);
                        int      newNumberOfArt = ++numberOfArt;
                        string   sessionString  = $"{artNr};{newNumberOfArt}";
                        controller.HttpContext.Session.SetString(numberOfSame.ToString(), sessionString);
                    }
                }
            }
        }