Пример #1
0
        /// <summary>
        /// Increments the quantity of a product in the shopping cart
        /// </summary>
        /// <param name="product">The Product whose quantity to increment</param>
        public OrderDetail IncrementProduct(ProductBase product)
        {
            OrderDetail orderDetail = Order.OrderDetails.Find(p => p.Product.Id == product.Id);

            if (orderDetail == null)
            {
                throw new Exception("Product is not in shopping cart!");
            }

            orderDetail.Quantity++;
            UpdateShippingCharges();
            return(orderDetail);
        }
Пример #2
0
        /// <summary>
        /// Removes all quantities of a product in the shopping cart, clears all promocodes if no items remain
        /// </summary>
        /// <param name="product">The Product to remove</param>
        public void RemoveProduct(ProductBase product)
        {
            OrderDetail orderDetail = Order.OrderDetails.Find(p => p.Product.Id == product.Id);

            if (!(orderDetail == null))
            {
                Order.OrderDetails.Remove(orderDetail);
            }

            if (Order.OrderDetails.Count == 0)
            {
                PromoCodes.Clear();
            }
        }
Пример #3
0
        /// <summary>
        /// Decrements the quantity of a product in the shopping cart, removes if none remaining after decrement
        /// </summary>
        /// <param name="product">The Product whose quantity to decrement</param>
        public OrderDetail DecrementProduct(ProductBase product)
        {
            OrderDetail orderDetail = Order.OrderDetails.Find(p => p.Product.Id == product.Id);

            if (!(orderDetail == null) && orderDetail.Quantity > 0)
            {
                orderDetail.Quantity--;
            }
            if (orderDetail.Quantity == 0)
            {
                RemoveProduct(product);
            }
            UpdateShippingCharges();
            return(orderDetail);
        }
Пример #4
0
        /// <summary>
        /// Adds a product to the shopping cart
        /// </summary>
        /// <param name="product">The Product to add</param>
        public void AddProduct(ProductBase product)
        {
            if (Order.OrderDetails.Exists(p => p.Product.Id == product.Id))
            {
                throw new Exception("Product is already in shopping cart!");
            }

            var orderDetail = new OrderDetail()
            {
                Product      = product,
                PlacedInCart = DateTime.Now,
                Quantity     = 1,
                UnitPrice    = product.Price,
                Shipping     = product.Shipping
            };

            Order.OrderDetails.Add(orderDetail);
            UpdateShippingCharges();
        }