示例#1
0
        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;
            }
        }
示例#2
0
        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);
        }
示例#3
0
 public void FinishOrder()
 {
     CurrentOrder.IsSent = true;
     CurrentBasket.Clear();
 }