예제 #1
0
        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(OrderNumber))
            {
                throw new ValidationErrorException(nameof(OrderNumber));
            }
            if (TotalValue < 0)
            {
                throw new ValidationErrorException(nameof(TotalValue));
            }
            if (Customer == null)
            {
                throw new ValidationErrorException(nameof(Customer));
            }
            Customer.Validate();

            if (ShippingAddress == null)
            {
                throw new ValidationErrorException(nameof(ShippingAddress));
            }
            ShippingAddress.Validate();

            if (OrderLines == null || !OrderLines.Any())
            {
                throw new ValidationErrorException(nameof(OrderLines));
            }

            OrderLines.ForEach(o => o.Validate());
        }
예제 #2
0
        private void CalculateSubtotalPrice()
        {
            OrderLines.ForEach(line => line.CalculatePrice());
            var subtotal = OrderLines
                           .Aggregate(0.0, (i, line) => i + line.Price);

            SubtotalPrice = Math.Round(subtotal, 2);
        }