Пример #1
0
        /// <summary>
        /// Main loop of application
        /// </summary>
        public void RunApplication()
        {
            var originalForegroundColor = Console.ForegroundColor;

            Console.WriteLine("Hello User!");
            Console.WriteLine("Welcome to MVVM bank");
            Console.ReadKey();
            var loopStatus = true;

            while (loopStatus)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                foreach (var msg in UserUpdates)
                {
                    Console.WriteLine(msg);
                }

                UserUpdates.Clear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Choose options:");
                Console.WriteLine("1. Add customer");
                Console.WriteLine("2. Deposit money to account");
                Console.WriteLine("3. Withdraw money from account");
                Console.WriteLine("4. Check account balance");
                Console.WriteLine("5. Exit");
                int inputValue = GetUserInput();

                switch (inputValue)
                {
                case 1:
                {
                    Console.WriteLine("Adding customer");
                    Console.WriteLine("Enter customer name : ");
                    vm.AddCustomer(Console.ReadLine());
                }
                break;

                case 2:
                {
                    Console.WriteLine("Depositing money");
                    Console.WriteLine("Enter valid account number : ");
                    var accNo = GetUserInput();
                    Console.WriteLine("Enter amount to deposit : ");
                    var amount = GetUserInput_D();
                    vm.DepositMoney(Convert.ToUInt32(accNo), amount);
                }
                break;

                case 3:
                {
                    Console.WriteLine("Withdrawing money");
                    Console.WriteLine("Enter valid account number : ");
                    var accNo = GetUserInput();
                    Console.WriteLine("Enter amount to deposit : ");
                    var amount = GetUserInput_D();
                    vm.WithdrawMoney(Convert.ToUInt32(accNo), amount);
                }
                break;

                case 4:
                {
                    Console.WriteLine("Checking account balance");
                    Console.WriteLine("Enter valid account number : ");
                    var accNo = GetUserInput();
                    Console.WriteLine(string.Format("For account {0} balance is : {1}", accNo, vm.CheckBalance(Convert.ToUInt32(accNo))));
                    Console.ReadKey();
                }
                break;

                default:
                    loopStatus = false;
                    break;
                }
            }

            Console.ForegroundColor = originalForegroundColor;
        }