Example #1
0
        /// <summary>
        /// Adds the specified product to the cart
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="quantity">The product's quantity to be added to the cart</param>
        /// <exception cref="ProductIsNotForSaleException">Thrown if the product is not for sale</exception>
        public void AddProductToCart(int productId, int quantity)
        {
            var product = ActiveContext.Products
                          .Where(p => p.Id == productId)
                          .SingleOrDefault();

            if (product == null || product.IsDiscontinued)
            {
                throw new ProductIsNotForSaleException();
            }
            CurrentCart.AddProduct(product.Id, quantity, product.UnitPrice.Value);
        }