예제 #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
        void SaveProduct(Product product)
        {
            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(product)) // if is valid
            {
                _productRepository.Add(product);
                _productRepository.UnitOfWork.Commit();
            }
            else //if not valid, throw validation errors
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(product));
        }
예제 #3
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;
        }