public bool CanPlaceOrder(decimal expectedTotalCost, decimal expectedShippingCost)
        {
            //An order must have at least one line
            if (!OrderLines.Any())
            {
                return(false);
            }

            //All products must be available to order
            foreach (var line in OrderLines)
            {
                if (!_productAvailabilityService.CheckProductAvailability(line.Product.Stockcode, line.Quantity))
                {
                    return(false);
                }
            }

            //The calculated costs must match the expected ones
            CalculateShippingCost();
            CalculateTotalCost();
            if (TotalCost != expectedTotalCost || ShippingCost != expectedShippingCost)
            {
                return(false);
            }

            //if all checks succeeded, return true
            return(true);
        }
예제 #2
0
        private bool CanPlaceOrder(PlaceOrderRequest request)
        {
            //An order must have at least one line
            if (!request.Order.OrderLines.Any())
            {
                return(false);
            }

            //All products must be available to order
            foreach (var line in request.Order.OrderLines)
            {
                if (!_productAvailabilityService.CheckProductAvailability(line.Product.Stockcode, line.Quantity))
                {
                    return(false);
                }
            }

            //The calculated costs must match the expected ones
            var shippingCost = _costCalculatorService.CalculateShippingPrice(request.Order.OrderLines.Select(x => x.Product).ToList(),
                                                                             request.Order.ShippingAddress);
            var totalCost = _costCalculatorService.CalculateTotalPrice(request.Order.OrderLines.ToList(), request.Order.PromotionCode);

            if (totalCost != request.ExpectedTotalCost || shippingCost != request.ExpectedShippingCost)
            {
                return(false);
            }

            //if all checks succeeded, return true
            return(true);
        }