Esempio n. 1
0
        public decimal CalculateDiscount(string code, Order order)
        {
            if (code == null)
            {
                throw new ArgumentNullException(nameof(code));
            }
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var coupon = _discountCouponRepositoryQuery.GetByCode(code);

            return(order.Total - (order.Total * coupon.Discount));
        }
Esempio n. 2
0
        public void ProcessOrder(string email, PaymentMethod paymentMethod, Payment payment,
                                 Address address, string code)
        {
            var shoppingCart = _shoppingCartService.GetByCustomer(email);

            var order    = OrderFactory.CreateOrder(shoppingCart);
            var shipping = Shipping.Create(address);
            var coupon   = _discountCouponRepositoryQuery.GetByCode(code);

            order.ChangePayment(payment);
            order.ChangePaymentMethod(paymentMethod);
            order.ChangeShipping(shipping);
            order.ApplyDiscountCoupon(coupon);

            _orderRepository.Add(order);
        }