Esempio n. 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);
        }
Esempio n. 2
0
        private void HandleNewCartItem(ShopCartItem item)
        {
            var cartItem = new ShopCartClient(_user.GetUserId());

            cartItem.AddItem(item);

            ValidatingShopCart(cartItem);
            _context.ShopCartClients.Add(cartItem);
        }
Esempio n. 3
0
        private bool ValidatingShopCart(ShopCartClient shopCart)
        {
            if (shopCart.IsValid())
            {
                return(true);
            }

            shopCart.ValidationResult.Errors.ToList().ForEach(e => AddProcessingError(e.ErrorMessage));
            return(false);
        }
Esempio n. 4
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);
        }