Пример #1
0
        public Cart AddProduct(Guid productId, Guid cartId)
        {
            var cart    = _cartsCollection.FindById(cartId);
            var product = _productHandler.Get(productId);

            if (cart != null && product != null)
            {
                if (cart.Products.ContainsKey(product.ProductId.ToString()))
                {
                    cart.Products[product.ProductId.ToString()].Quantity += 1;
                }
                else
                {
                    cart.Products.Add(product.ProductId.ToString(), product);
                }
                cart.TotalPrice += product.ProductPrice;
                var updatedCart = new Cart {
                    CartId     = cart.CartId,
                    CartClosed = cart.CartClosed,
                    Products   = cart.Products,
                    TotalPrice = cart.TotalPrice
                };
                _cartsCollection.Update(updatedCart);
                return(updatedCart);
            }
            return(null);
        }
Пример #2
0
        public async Task <Product> Get(Guid productId)
        {
            var productFromDb = await Task.Run(() => {
                return(_productHandler.Get(productId));
            });

            return(productFromDb);
        }