/// <summary>
        /// Adds an item to the cart
        /// Level: Logic
        /// </summary>
        /// <param name="UserID">The User ID</param>
        /// <param name="ProductID">The Product ID</param>
        /// <param name="Quantity">The Quantity</param>
        public void AddToCart(Guid UserID, Guid ProductID, int Quantity)
        {
            try
            {
                ShoppingCartRepository myRepository = new ShoppingCartRepository(false);

                if (myRepository.ItemExists(ProductID, UserID))
                {
                    myRepository.ChangeQuantity(ProductID, UserID, Quantity);
                }
                else
                {
                    ShoppingCart myShoppingCartItem = new ShoppingCart();

                    myShoppingCartItem.UserFK    = UserID;
                    myShoppingCartItem.ProductFK = ProductID;
                    myShoppingCartItem.Quantity  = Quantity;

                    myRepository.AddToCart(myShoppingCartItem);
                }
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }
        public ActionResult AddToCart(int id)
        {
            var addProduct = productRepository.GetById(id);
            var cart       = shoppingCartRepository.GetCart(User.Identity.GetUserId());

            shoppingCartRepository.AddToCart(cart, addProduct);
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public RedirectToActionResult AddToShoppingCart(string bookId)
        {
            var selectedBook = _bookRepository.GetBookEntityById(bookId);

            if (selectedBook != null)
            {
                _shoppingCart.AddToCart(selectedBook, 1);
            }
            return(RedirectToAction("Index"));
        }