Exemplo n.º 1
0
        public static void PurchaseItem(User user)
        {
            ListItems();
            Console.WriteLine("Enter the number of the item you want to purchase");
            if (int.TryParse(Console.ReadLine(), out var itemSelected))
            {
                itemSelected -= 1; // Get the array index

                foreach (var t in _items)
                {
                    if (user.CreditCard < _items[itemSelected].ItemPrice)
                    {
                        Console.WriteLine("Sorry, but you need to withdraw money to your creditcard.");
                        Menu.DisplayMenu();
                        break;
                    }
                    if (_items[itemSelected].ItemInventory == 0)
                    {
                        Console.WriteLine($"Sorry, but {_items[itemSelected].ItemName} seems to be sold out");
                        PurchaseItem(user);
                        break;
                    }
                    Console.WriteLine($"Thank you! Your order of {_items[itemSelected].ItemName} for {_items[itemSelected].ItemPrice}$ will be delivered as soon as possible.");
                        _items[itemSelected].ItemPrice -= user.CreditCard;
                        break;
                }
            }
            else
                Console.WriteLine("You need to enter a number");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Menu      menu       = new Menu();
            Bank      bank       = new Bank();
            Inventory inventory  = new Inventory();
            int       balance    = 0;
            int       creditCard = 0;
            User      user       = new User(balance, creditCard);

            Menu.DisplayMenu();
            while (true)
            {
                var input = Console.ReadLine();
                {
                    switch (input)
                    {
                    case "1":
                        try
                        {
                            Console.Clear();
                            Inventory.PurchaseItem(user);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }

                        break;

                    case "2":
                        try
                        {
                            Bank.ShowBalance(user);
                            Menu.DisplayMenu();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }

                        break;

                    case "3":
                        try
                        {
                            Console.WriteLine("How much would you like to withdraw to your creditcard?");
                            int.TryParse(Console.ReadLine(), out var withdrawAmount);
                            Bank.Withdraw(withdrawAmount, user);
                            Menu.DisplayMenu();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }

                        break;

                    default:
                        Console.WriteLine("You need to input 1. To order items, 2. To Show balance or 3. to Withdraw money");
                        break;
                    }
                }
            }
        }