Beispiel #1
0
        public async Task <IActionResult> AddToShoppingCartDisplayProducts(DisplayProductsViewModel model)
        {
            var selectedProduct = _productRepository.GetProduct(model.Id);
            var user            = await _userManager.GetUserAsync(HttpContext.User);

            if (selectedProduct != null)
            {
                _shoppingCart.AddToCart(selectedProduct, model.Quantity, user.Id);
            }
            return(RedirectToAction("DisplayProducts", "Product", new { id = 1 }));
        }
Beispiel #2
0
        public IActionResult DisplayProducts(int Id)
        {
            DisplayProductsViewModel model = new DisplayProductsViewModel();

            List <ProductModel> Products = (_productRepository.GetAllProducts()).ToList();

            model.CurrentType = Id;

            //If user sorts to diffrent categort reset item counter
            if (model.CurrentType != Id)
            {
                model.ItemCount = 0;
            }

            string type_choice = "";

            switch (Id)
            {
            case 1: type_choice = "All"; break;

            case 2: type_choice = "Vegetables"; break;

            case 3: type_choice = "Fruits"; break;

            case 4: type_choice = "Meats"; break;

            case 5: type_choice = "Fish"; break;

            case 6: type_choice = "Drinks"; break;

            case 7: type_choice = "Creams"; break;

            case 8: type_choice = "DatesNuts"; break;

            case 9: type_choice = "Bakeary"; break;

            case 10: type_choice = "Baby"; break;

            case 11: type_choice = "Other"; break;
            }

            //If to showcase all products there is no if() statement
            if (type_choice == "All")
            {
                for (int i = 0; i < 15; i++)
                {
                    model.Products.Add(Products[i]);
                    model.ItemCount++;

                    //If there is more than 15 items allow user to scroll for them
                    if (i + 1 == 15 && (i + 1 >= Products.Count))
                    {
                        model.ShowNext = true;
                    }

                    //If there is no more products
                    if (Products.Count == i + 1)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < 15; i++)
                {
                    if (Products[i].Type == type_choice)
                    {
                        model.Products.Add(Products[i]);
                    }
                    model.ItemCount++;

                    //If there is more than 15 items allow user to scroll for them
                    if (i + 1 == 15 && (i + 1 >= Products.Count))
                    {
                        model.ShowNext = true;
                    }

                    //If there is no more products
                    if (Products.Count == i + 1)
                    {
                        break;
                    }
                }
            }

            return(View(model));
        }