Exemple #1
0
        public IActionResult ProductItem(string id)
        {
            if (id.Length == 5 || id.Length == 7)
            {
                ProductProductItemVM productToView = webShopDBContext.GetProductToView(id);

                return(View(productToView));
            }
            else
            {
                return(View());//FEL!
            }
        }
Exemple #2
0
        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);
                    }
                }
            }
        }
Exemple #3
0
        internal ProductProductItemVM GetProductToView(string articleNum)
        {
            string artNrShort;
            int    specificColor = int.Parse(articleNum[4].ToString());

            if (articleNum.Length == 5)
            {
                Product product = this.Product.Where(p => p.ProdArtNr.StartsWith(articleNum)).Where(p => p.ProdQty > 0).First();

                artNrShort = articleNum;
            }
            else
            {
                artNrShort = articleNum.Remove(articleNum.Length - 2);
            }

            Product currentProduct = this.Product.First(p => p.ProdArtNr.Remove(p.ProdArtNr.Length - 2) == artNrShort);

            var colorArray = GetAllColors(artNrShort.Remove(artNrShort.Length - 1));
            var sizeArray  = GetAllSizes(currentProduct.ProdBrandId, currentProduct.ProdModelId, colorArray.First(c => c.Value == specificColor.ToString()).Text);
            var imageArray = GetAllImages(artNrShort);

            var prodModel = Model.First(m => m.ModelId == currentProduct.ProdModelId).ModelName;
            var prodBrand = Brand.First(b => b.BrandId == currentProduct.ProdBrandId).BrandName;


            var ret = new ProductProductItemVM
            {
                ArticleNum    = artNrShort,
                ColorArray    = colorArray,
                Description   = currentProduct.ProdDescription,
                ImageArray    = imageArray,
                Price         = Convert.ToInt32(currentProduct.ProdPrice),
                Model         = prodModel,
                Brand         = prodBrand,
                SizeArray     = sizeArray,
                SelectedColor = specificColor.ToString()
            };

            return(ret);
        }
Exemple #4
0
        public IActionResult ProductItem(ProductProductItemVM addProductToCart)
        {
            DataManager.AddToCart(this, addProductToCart, webShopDBContext);

            return(RedirectToAction(nameof(ProductItem)));
        }