public static async Task <Cart> InitCart(this Cart cart, ICatalogGateway catalogGateway, bool isPopulatePrice = false) { if (cart == null) { cart = new Cart(); } if (isPopulatePrice == false) { cart.CartItemPromoSavings = 0; cart.CartTotal = 0; cart.ShippingPromoSavings = 0; cart.ShippingTotal = 0; cart.CartItemTotal = 0; } if (cart.CartItems != null) { foreach (var item in cart.CartItems) { var product = await catalogGateway.GetProductByIdAsync(item.Product.ProductId); if (product == null) { throw new Exception("Could not find product."); } item.Product = new Product(product.Id, product.Name, product.Price, product.Desc); item.Price = product.Price; item.PromoSavings = 0; } } return(cart); }
public RelationalDatabaseDataSet GetAll(ICatalogGateway gateway) { _logger.Trace(Strings.TableModuleCall); Guard.Against.Null(gateway, nameof(gateway)); return(gateway.FindAllCatalogs()); }
public RequestHandler( IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf, ICatalogGateway catalogGateway, INoTaxPriceCalculator priceCalculator) : base(uow, qrf) { _catalogGateway = catalogGateway; _priceCalculator = priceCalculator; }
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; }
public CartServiceImpl(IServiceProvider resolver) { _queryFactory = resolver.GetService <IQueryRepositoryFactory>(); _commandFactory = resolver.GetService <IUnitOfWorkAsync>(); _catalogGateway = resolver.GetService <ICatalogGateway>(); _shippingGateway = resolver.GetService <IShippingGateway>(); _promoGateway = resolver.GetService <IPromoGateway>(); }
public CartRequestHandler( ICatalogGateway cgw, IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf, NoTaxCaculator priceCalculator) : base(uow, qrf) { _catalogGateway = cgw; _priceCalculator = priceCalculator; }
public void FillBy(RelationalDatabaseDataSet dataSet, ICatalogGateway catalogGateway, CatalogName[] catalogNameCollection) { _logger.Trace(Strings.TableModuleCall); Guard.Against.Null(catalogGateway, nameof(catalogGateway)); Guard.Against.NullOrEmptyCollection(catalogNameCollection, nameof(catalogNameCollection)); RelationalDatabaseDataSet results = catalogGateway.FindCatalogBy(catalogNameCollection); dataSet.Merge(results); }
public RelationalDatabaseDataSet GetBy(ICatalogGateway catalogGateway, CatalogName[] catalogNameCollection) { _logger.Trace(Strings.TableModuleCall); Guard.Against.Null(catalogGateway, nameof(catalogGateway)); Guard.Against.NullOrEmptyCollection(catalogNameCollection, nameof(catalogNameCollection)); var dataSet = new RelationalDatabaseDataSet(); FillBy(dataSet, catalogGateway, catalogNameCollection); return(dataSet); }
public RelationalDatabaseDataSet GetCatalogs(string dataSource, string connectionString) { Guard.Against.NullOrEmpty(dataSource, nameof(dataSource)); Guard.Against.NullOrEmpty(connectionString, nameof(connectionString)); try { ICatalogGateway gateway = _tableGatewayFactoryFunc(dataSource, connectionString); return(_tableModule.Catalog.GetAll(gateway)); } catch (Exception ex) { _logger.LogError(ex.Message); throw; } }
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); }
public RequestHandler(ICatalogGateway cgw, IQueryRepositoryFactory qrf, NoTaxCaculator priceCalculator) : base(qrf) { _catalogGateway = cgw; _priceCalculator = priceCalculator; }
public RequestHandler(ICatalogGateway cgw, IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf) : base(uow, qrf) { _catalogGateway = cgw; }