public void Add(Goods goods, int amount) { if (goods.IsEighteen && CurrentUser.Age < 18) { throw new ArgumentException("You are not old enough to order alcohol."); } if (goods == null) { throw new ArgumentNullException("Product is null.", nameof(goods)); } if (amount <= 0) { throw new ArgumentException("Amount should be positive.", nameof(amount)); } CurrentOrder.AddToBasket(goods.Id, amount); Goods temp = null; foreach (var item in CurrentBasket) { if (item.Key.Id == goods.Id) { temp = item.Key; } } if (temp == null) { CurrentBasket.Add(goods, amount); } else { CurrentBasket[temp] += amount; } }
public void Delete(Goods goods) { if (goods == null) { throw new ArgumentNullException("Product is null.", nameof(goods)); } Goods temp = null; foreach (var item in CurrentBasket) { if (item.Key.Id == goods.Id) { temp = item.Key; } } if (temp == null) { throw new ArgumentException("There is no this type of product in basket."); } CurrentBasket.Remove(temp); }
public void FinishOrder() { CurrentOrder.IsSent = true; CurrentBasket.Clear(); }