Пример #1
0
        /// <summary>
        /// Sets a product in this order line
        /// </summary>
        /// <param name="product">The related product for this order line</param>
        public void SetProduct(Product product)
        {
            if (product == null
                ||
                product.IsTransient())
            {
                throw new ArgumentNullException(Messages.exception_CannotAssociateTransientOrNullProduct);
            }

            //fix identifiers
            this.ProductId = product.Id;
            this.Product = product;
        }
Пример #2
0
        /// <summary>
        /// Create a new order line
        /// </summary>
        /// <param name="product">The associated product</param>
        /// <param name="amount">the number of items</param>
        /// <param name="discount">the selected discount for this line</param>
        /// <returns>The new order line</returns>
        public OrderLine CreateOrderLine(Product product, int amount, decimal unitPrice, decimal discount)
        {
            //check precondition
            if (amount <= 0
               ||
                product.IsTransient())
            {
                throw new ArgumentException(Messages.exception_InvalidDataForOrderLine);
            }

            //check discount values
            if (discount < 0)
                discount = 0;

            if (discount > 100)
                discount = 100;

            //create and return order line

            var line =  new OrderLine()
            {
                OrderId = this.Id,
                Amount = amount,
                Discount = discount,
                UnitPrice = unitPrice
            };

            line.SetProduct(product);

            return line;
        }