public ShoppingCartItem AddProductToCart(string shoppingCartId, Product product) { lock (_lock) { ShoppingCart shoppingCart = GetById(shoppingCartId); if (shoppingCart == null) { shoppingCart = new ShoppingCart(new List<ShoppingCartItem>()) { ShoppingCartId = shoppingCartId, Currency = "USD", TaxRate = .09 }; _shoppingCarts[shoppingCartId] = shoppingCart; } ShoppingCartItem item = shoppingCart.ShoppingCartItems.FirstOrDefault(c => c.Product.ProductNumber == product.ProductNumber); if (item == null) { item = new ShoppingCartItem { Id = product.ProductNumber, Product = product, Quantity = 1, Currency = shoppingCart.Currency }; shoppingCart.ShoppingCartItems.Add(item); } else { item.Quantity++; } UpdatePrices(shoppingCart); return item; } }
ShoppingCartItem IShoppingCartRepository.AddProductToCart(string shoppingCartId, Product product) { return AddProductToCartDelegate(shoppingCartId, product); }