public void RemoveProduct(BasketProduct basketProduct) { if (basketProduct == null) { return; } _products.Remove(basketProduct); NotifyProperties(); }
public void IncreaseQuantity(BasketProduct basketProduct) { if (basketProduct.Quantity + 1 > basketProduct.Product.Quantity) { return; } basketProduct.Quantity++; NotifyProperties(); }
public void DecreaseQuantity(BasketProduct basketProduct) { if (basketProduct.Quantity - 1 < 0) { return; } basketProduct.Quantity--; NotifyProperties(); }
public void AddBasketProduct(BasketProduct basketProductToAdd) { if (basketProductToAdd.Product == null) { throw new IllegalProductInsertion("Vous devez sélectionner un produit avant de l'ajouter !"); } var idProduct = basketProductToAdd.Product.IDProduct; var quantityToAdd = basketProductToAdd.Quantity; if (quantityToAdd <= 0) { throw new IllegalProductInsertion("La quantité doit-être positive !"); } if (quantityToAdd > basketProductToAdd.Product.Quantity) { throw new IllegalProductInsertion("La quantité ne peut pas être suppérieure au stock !\n" + $"Vous demandez {quantityToAdd} {basketProductToAdd.Product.Name} alors qu'il n'en reste que {basketProductToAdd.Product.Quantity}."); } //If the product is already on the basket if (_products.Select(x => x.Product.IDProduct).Contains(idProduct)) { foreach (BasketProduct t in _products) { if (t.Product.IDProduct == idProduct) { if ((t.Quantity + 1) <= basketProductToAdd.Product.Quantity) { t.Quantity += quantityToAdd; } else { throw new IllegalProductInsertion("La quantité ne peut pas être suppérieure au stock !\n" + $"Vous demandez {basketProductToAdd.Product.Quantity + 1} {basketProductToAdd.Product.Name} alors qu'il n'en reste que {basketProductToAdd.Product.Quantity}."); } } } } else { _products.Add(basketProductToAdd); } NotifyProperties(); }
public void DecreaseQuantity(BasketProduct basketProduct) { int tmp = basketProduct.Quantite - 1; if (tmp == 0) { RemoveProduct(basketProduct); return; } else if (tmp < 0) { return; } basketProduct.Quantite--; NotifyProperties(); }