Пример #1
0
        /// <summary>
        /// Handles new transactions
        /// </summary>
        private void MakeTransaction()
        {
            const int WITHDRAW = 1;
            const int DEPOSIT  = 2;

            Transaction newTransaction = new Transaction();
            int         selection;
            decimal     transferAmount;
            bool        bValidDecimal = true;
            List <int>  rules         = new List <int> {
                WITHDRAW, DEPOSIT
            };

            Console.Clear();
            AccountView.AccountAmount(mcAccount.mcAccountBalance.mBalance.ToString());

            selection = ConsoleHelper.ValidateSelection(AccountView.TransactionTypeMenu, rules);

            if (selection == WITHDRAW)
            {
                newTransaction.TransactionType = Transaction.Type.WITHDRAW;
            }
            else
            {
                newTransaction.TransactionType = Transaction.Type.DEPOSIT;
            }

            do
            {
                Console.Clear();
                if (!bValidDecimal)
                {
                    ConsoleHelper.ConsoleWriteColor(ConsoleColor.Red, "Invalid Amount, must be a decimal number", true);
                }
                AccountView.TransactionAmount();
            } while (!(bValidDecimal = decimal.TryParse(Console.ReadLine(), out transferAmount)));

            newTransaction.Amount = new Money(transferAmount);
            Task.Run(() => TransactionEventRaised.Invoke(newTransaction)).Wait();
        }