Exemplo n.º 1
0
        public static bool UpdateCart(int userId, int productId, int quantity)
        {
            Product p = ProductHandler.GetProduct(productId);

            if (quantity > p.Stock)
            {
                return(false);
            }

            CartRepository.UpdateCart(userId, productId, quantity);
            return(true);
        }
Exemplo n.º 2
0
        public static bool DeleteCart(int userId, int productId)
        {
            Product p = ProductHandler.GetProduct(productId);
            User    u = UserHandler.GetUser(userId);

            if (u != null && p != null)
            {
                CartRepository.DeleteCart(userId, productId);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public static bool InsertCart(int userId, int productId, int quantity)
        {
            Product p = ProductHandler.GetProduct(productId);
            Cart    c = CartRepository.GetCart(userId, productId);

            if (quantity > p.Stock)
            {
                return(false);
            }

            if (c != null)
            {
                int new_quantity = c.Quantity + quantity;
                CartRepository.UpdateCart(userId, productId, new_quantity);
                return(true);
            }

            CartRepository.InsertCart(userId, productId, quantity);
            return(true);
        }