Exemplo n.º 1
0
        public async Task UpdateCartItemAsync(IShoppingCartItemDTO obj)
        {
            // TODO: Remove this demonstration wait.
            await Task.Delay(300);

            ShoppingCart cart = await _contextDAL._dbContext.ShoppingCarts.FirstOrDefaultAsync(o => o.ShoppingCartId == obj.ShoppingCartId);

            ShoppingCartItem item = cart.Items.FirstOrDefault(o => o.Product.ProductId == obj.Product.ProductId);

            item.Quantity = obj.Quantity;
            item.Updated  = DateTime.Now;
            await _contextDAL._dbContext.SaveChangesAsync();
        }
        public async Task <ShoppingCartItem> AddProductToCartAsync(ShoppingCart shoppingCart, Product product, int quantity)
        {
            IShoppingCartItemDTO item = await _contextBLL.DAL.ShoppingCarts.AddProductToCartAsync(shoppingCart.SessionId, product.ProductId, quantity);

            return(new ShoppingCartItem(_contextBLL, item));
        }
        }                              // hide the constructor

        public ShoppingCartItem(ContextBLL contextBLL, IShoppingCartItemDTO dto)
        {
            _contextBLL = contextBLL;
            _dto        = dto;
        }