Пример #1
0
 public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf,
                       ICatalogGateway catalogGateway, IShippingGateway shippingGateway,
                       IPromoGateway promoGateway) : base(uow, qrf)
 {
     _catalogGateway  = catalogGateway;
     _shippingGateway = shippingGateway;
     _promoGateway    = promoGateway;
 }
 public RequestHandler(ICatalogGateway cgw, IQueryRepositoryFactory qrf,
                       IShippingGateway shippingGateway, IPromoGateway promoGateway)
     : base(qrf)
 {
     _catalogGateway  = cgw;
     _shippingGateway = shippingGateway;
     _promoGateway    = promoGateway;
 }
Пример #3
0
        public CartServiceImpl(IServiceProvider resolver)
        {
            _queryFactory   = resolver.GetService <IQueryRepositoryFactory>();
            _commandFactory = resolver.GetService <IUnitOfWorkAsync>();

            _catalogGateway  = resolver.GetService <ICatalogGateway>();
            _shippingGateway = resolver.GetService <IShippingGateway>();
            _promoGateway    = resolver.GetService <IPromoGateway>();
        }
Пример #4
0
        public async Task <Cart> CalculateCartAsync(
            TaxType taxType, ICatalogGateway catalogGateway,
            IPromoGateway promoGateway, IShippingGateway shippingGateway)
        {
            if (CartItems != null && CartItems?.Count() > 0)
            {
                CartItemTotal = 0.0D;
                foreach (var cartItem in CartItems)
                {
                    var product = await catalogGateway.GetProductByIdAsync(cartItem.Product.ProductId);

                    if (product == null)
                    {
                        throw new Exception("Could not find product.");
                    }

                    cartItem
                    .FillUpProductInfo(product.Name, product.Price, product.Desc)
                    .ChangePrice(product.Price);

                    CartItemPromoSavings = CartItemPromoSavings + cartItem.PromoSavings * cartItem.Quantity;
                    CartItemTotal        = CartItemTotal + cartItem.Product.Price * cartItem.Quantity;
                }

                shippingGateway.CalculateShipping(this);
            }

            promoGateway.ApplyShippingPromotions(this);

            switch (taxType)
            {
            case TaxType.NoTax:
                CartTotal = CartItemTotal + ShippingTotal;
                break;

            case TaxType.TenPercentage:
                var cartTotal = CartItemTotal + ShippingTotal;
                CartTotal = cartTotal * 10 / 100 + cartTotal;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(taxType), taxType, null);
            }

            return(this);
        }
Пример #5
0
 protected PriceCalculatorContext(IPromoGateway promoGateway, IShippingGateway shippingGateway)
 {
     _promoGateway    = promoGateway;
     _shippingGateway = shippingGateway;
 }
Пример #6
0
 public NoTaxCaculator(IPromoGateway promoGateway, IShippingGateway shippingGateway)
     : base(promoGateway, shippingGateway)
 {
 }
 public TenPercentTaxCalculator(IPromoGateway promoGateway, IShippingGateway shippingGateway)
     : base(promoGateway, shippingGateway)
 {
 }