Beispiel #1
0
        public bool TransferMoney(uint accountFromId, uint accountToId, ulong amount)
        {
            Account fromAccount = Accounts.FirstOrDefault(x => x.GetID() == accountFromId);
            Account toAccount   = Accounts.FirstOrDefault(x => x.GetID() == accountToId);

            if (fromAccount.GetBalance() < amount)
            {
                return(false);
            }
            fromAccount.WithdrawMoney(amount);
            toAccount.DepositMoney(amount);

            return(true);
        }
Beispiel #2
0
        static async Task SimulateAccountSynchronization()
        {
            var account = new Account();

            account.Deposit(10, DateTime.Now);
            var tasks = new Task[2];

            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = Task.Run(() => Update(account));
            }

            await Task.WhenAll(tasks);

            Console.WriteLine($"Account's balance is {account.GetBalance()}");
        }
Beispiel #3
0
        private static void ShowAccountMenu(Account account)
        {
            int     choice;
            decimal amount;
            var     showMenu = true;

            while (showMenu)
            {
                Console.WriteLine($"\n***** Account {account.Number} *****");
                Console.WriteLine("1. Check balance");
                Console.WriteLine("2. Withdraw");
                Console.WriteLine("3. Deposit");
                Console.WriteLine("4. Add account owner");
                Console.WriteLine("5. All transactions");
                Console.WriteLine("6. Exit");
                Console.WriteLine("**************************\n");
                Console.WriteLine("Enter your choice: ");

                choice = int.Parse(Console.ReadLine());

                try
                {
                    switch (choice)
                    {
                    case 1:
                        Console.WriteLine($"Your balance is : {account.GetBalance()} ");
                        break;

                    case 2:
                    {
                        Console.WriteLine("enter the amount to withdrow: ");
                        amount = decimal.Parse(Console.ReadLine());
                        account.Withdrawal(amount, DateTime.Now);
                    }
                    break;

                    case 3:
                    {
                        Console.WriteLine("enter the amount to deposit: ");
                        amount = decimal.Parse(Console.ReadLine());
                        account.Deposit(amount, DateTime.Now);
                    }
                    break;

                    case 4:
                    {
                        Console.WriteLine("enter owner id");
                        int ownerId = int.Parse(Console.ReadLine());
                        Console.WriteLine("enter owner first name");
                        string firstName = Console.ReadLine();
                        Console.WriteLine("enter owner last name");
                        string lastName = Console.ReadLine();

                        var owner = new Owner(ownerId, firstName, lastName);
                        account.AddAccountOwner(owner);
                        Console.WriteLine("owner added successfully");
                    } break;

                    case 5:
                    {
                        Console.WriteLine(account.GetAccountTransactions());
                    } break;

                    case 6:
                    {
                        Console.WriteLine("Good bye");
                        showMenu = false;
                    } break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.Write("Enter to continue");
                Console.ReadLine();
            }
        }