Esempio n. 1
0
        public static string ClearCart(ISession session)
        {
            var cart = ShoppingCartManager.GetCart(session);

            cart.ClearAllItems();
            return(ShoppingCartManager.SaveCart(session, cart));
        }
Esempio n. 2
0
        public static OrderProduct AddItemById(ISession session, int id)
        {
            var cart    = ShoppingCartManager.GetCart(session);
            var product = cart.AddProductById(id);

            ShoppingCartManager.SaveCart(session, cart);

            return(product);
        }
Esempio n. 3
0
        public static OrderProduct DecrementQuanityForItemById(ISession session, int id)
        {
            var cart    = ShoppingCartManager.GetCart(session);
            var product = ShoppingCartManager.ItemById(session, id);

            if (product != null)
            {
                var orderProduct = cart.DecrementQuantityForOrderByProductId(id);
                ShoppingCartManager.SaveCart(session, cart);
                return(orderProduct);
            }
            return(null);
        }
Esempio n. 4
0
        public static Dictionary <string, int> GetQuantity(ISession session, int id)
        {
            var cart    = ShoppingCartManager.GetCart(session);
            var product = ShoppingCartManager.ItemById(session, id);

            if (product != null)
            {
                var dict = new Dictionary <string, int>();
                dict["quantity"] = product.Quantity;
                return(dict);
            }

            return(null);
        }
Esempio n. 5
0
        public static bool RemoveItemById(ISession session, int id)
        {
            var cart    = ShoppingCartManager.GetCart(session);
            var product = ShoppingCartManager.ItemById(session, id);

            if (product != null)
            {
                cart.RemoveProductById(id);
                ShoppingCartManager.SaveCart(session, cart);
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        public static void SetQuantityForItemById(ISession session, int id, int quantity)
        {
            var cart    = ShoppingCartManager.GetCart(session);
            var product = ShoppingCartManager.ItemById(session, id);

            if (product != null)
            {
                // TODO: Use the new methods from the models.
                int index = cart.Order.OrderProducts.IndexOf(product);
                if (index != -1 && cart.Order.OrderProducts.ElementAt(index) != null)
                {
                    cart.Order.OrderProducts[index].SetQuantity(quantity);
                    ShoppingCartManager.SaveCart(session, cart);
                }
            }
        }
Esempio n. 7
0
        public static OrderProduct ItemById(ISession session, int id)
        {
            var cart  = ShoppingCartManager.GetCart(session);
            var order = cart.Order;

            if (order == null)
            {
                return(null);
            }
            var products = order.OrderProducts;

            if (products == null)
            {
                return(null);
            }
            return(products.FirstOrDefault(e => e.Id == id));
        }
Esempio n. 8
0
        public static void AddItem(ISession session, OrderProduct item)
        {
            var cart = ShoppingCartManager.GetCart(session);

            var existingItem = cart.Order.OrderProducts.FirstOrDefault(e => e.Id == item.Id);

            if (existingItem != null)
            {
                int index = cart.Order.OrderProducts.IndexOf(existingItem);
                cart.Order.OrderProducts[index].IncrementQuantity();
            }
            else
            {
                cart.Order.OrderProducts.Add(item);
            }

            SaveCart(session, cart);
        }