コード例 #1
0
        private async Task <ShopCartItem> GetValidShopCartItem(Guid productId, ShopCartClient shopCart, ShopCartItem item = null)
        {
            if (item != null && productId != item.ProductId)
            {
                AddProcessingError("Item doesn't match with to the informed");
                return(null);
            }

            if (shopCart == null)
            {
                AddProcessingError("Shop cart not found");
                return(null);
            }

            var shopCartItem = await _context.ShopCartItems
                               .FirstOrDefaultAsync(i => i.ShopCartId == shopCart.Id && i.ProductId == productId);

            if (shopCartItem == null || !shopCart.ShopCartItemExists(shopCartItem))
            {
                AddProcessingError("Item isn't on shop cart");
                return(null);
            }

            return(shopCartItem);
        }
コード例 #2
0
        private void HandlerExistentShopCart(ShopCartClient cart, ShopCartItem item)
        {
            var productItemExistent = cart.ShopCartItemExists(item);

            cart.AddItem(item);
            ValidatingShopCart(cart);

            if (productItemExistent)
            {
                _context.ShopCartItems.Update(cart.GetByProductId(item.ProductId));
            }
            else
            {
                _context.ShopCartItems.Add(item);
            }

            _context.ShopCartClients.Update(cart);
        }