Beispiel #1
0
 public void OrderValidation(Order order)
 {
     if (order == null)
     {
         throw new ArgumentNullException("Order doesn't exist!");             //проверка введенного количества товара
     }
     order.CheckCount();
     if (Balance < order.GetTotalPrice())
     {
         throw new InvalidOperationException("Not enough money");                                 // если недостаточно средств
     }
     Balance -= order.GetTotalPrice();
 }
Beispiel #2
0
        public void Update()
        {
            Console.Clear();
            Console.WriteLine($"Balance - {Machine.Balance}");
            Console.WriteLine();

            Console.WriteLine("Write command...");

            string command = Console.ReadLine();

            switch (command)
            {
            case "help":
                Console.WriteLine("list\n " +
                                  "order \n");
                break;

            case "list":
                foreach (Good good in Machine.GetProductList())
                {
                    Console.WriteLine($">{good.Name} [{good.Count}]");
                }
                break;

            case "order":
                Machine.Balance = SetMachineBalance();
                Console.WriteLine("Enter product name");
                string productName = NameVerification(Console.ReadLine());
                Console.WriteLine("Enter amount");
                int count = CountVerification(Console.ReadLine());

                Order order = new Order(Machine.Goods.GetProduct(productName), count);
                Machine.OrderValidation(order);
                Console.WriteLine($"Total price - {order.GetTotalPrice()}");

                Console.WriteLine($"Change is {Machine.ClearBalance(Machine.Balance)}");
                break;

            default:
                Console.WriteLine("Enter valid command");
                break;
            }
            Console.WriteLine("Press any button");
            Console.ReadKey();
        }