Пример #1
0
        //public void DeleteCartItem(CartItemViewModel cartItem)
        //{
        //    _cartList.Remove(cartItem);
        //    CartListChanged(this, null);
        //    RaisePropertyChanged(() => CartList);
        //}

        public void AddProductToCartList(ProductViewModel product, int quantities)
        {
            CartItemViewModel cartItem = _cartList.FirstOrDefault(c => c.Product.Id == product.Id);

            if (cartItem == null)
            {
                cartItem = new CartItemViewModel(product, quantities);
                _cartList.Add(cartItem);
                RaisePropertyChanged(() => CartList);
            }
            else
            {
                cartItem.AddQuantities(quantities);
            }
            product.DeductQuantities(quantities);
            CartListChanged?.Invoke(this, null);
        }