WebStore.WebStoreCatalogResponse WebStore.IWebStoreCatalogManager.ShowCatalog(int catalogId) { try { // Get the webstore catalog WebStore.WebStoreCatalog result = new WebStore.WebStoreCatalog(); ICatalogAccessor catalogAccessor = AccessorFactory.CreateAccessor <ICatalogAccessor>(); DTO.WebStoreCatalog accCatalog = catalogAccessor.Find(catalogId); // Get the webstore catalog products if (accCatalog != null) { DTOMapper.Map(accCatalog, result); DTO.Product[] catalogProducts = catalogAccessor.FindAllProductsForCatalog(catalogId); List <WebStore.ProductSummary> productList = new List <WebStore.ProductSummary>(); foreach (var catalogProduct in catalogProducts) { WebStore.ProductSummary product = new WebStore.ProductSummary(); DTOMapper.Map(catalogProduct, product); productList.Add(product); } result.Products = productList.ToArray(); return(new WebStore.WebStoreCatalogResponse() { Success = true, Catalog = result }); } return(new WebStore.WebStoreCatalogResponse() { Success = false, Message = "Catalog not found" }); } catch (Exception ex) { Logger.Error(ex); return(new WebStore.WebStoreCatalogResponse() { Success = false, Message = "There was a problem accessing the catalog" }); } }
public WebStoreCart GenerateCartPricing(Cart cart) { WebStoreCart result = new WebStoreCart(); // map the cart input to a webstore cart DTOMapper.Map(cart, result); // loop through all cart items, get the current price and apply to the cart item ICatalogAccessor catAccessor = AccessorFactory.CreateAccessor <ICatalogAccessor>(); foreach (WebStoreCartItem item in result.CartItems) { if (item.Quantity > 0) { // get the current unit price and update the cart item var product = catAccessor.FindProduct(item.ProductId); if (product != null) { decimal unitPrice = product.Price; decimal extendedPrice = Math.Round(unitPrice * item.Quantity, 2); // update the web store cart item.UnitPrice = unitPrice; item.ExtendedPrice = extendedPrice; // add the amount to the subtotal result.SubTotal += Math.Round(extendedPrice, 2); } else { Logger.Error("Invalid Product Id"); throw new ArgumentException("Invalid Product Id"); } } else { Logger.Error("Invalid item quantity"); throw new ArgumentException("Invalid item quantity"); } } // set the cart total to the subtotal result.Total = result.SubTotal; return(result); }
public CatalogProvider(ICatalogAccessor catalogAccessor, ILogger <CatalogProvider> logger) { _catalog = catalogAccessor; _logger = logger; }
public CatalogManager(ICatalogAccessor _catalogAccessor) { this._catalogAccessor = _catalogAccessor; }