Example #1
0
        private Account MakeAccount(string name, string id, float deposit, AccountType acctType)
        {
            Console.WriteLine("<<< Making an account for: [{0}] with initial deposit: [{1}] >>>", name, deposit);
            Account account = null;

            switch (acctType)
            {
            case AccountType.SIMPLE_CHECKING:
                account = new SimpleAccount(name, id, deposit);
                break;

            case AccountType.INTEREST_CHECKING:
                account = new InterestAccount(name, id, deposit);
                break;

            case AccountType.SAVINGS:
                account = new SavingsAccount(name, id, deposit);
                break;

            case AccountType.OTHER:
                throw new BankingException("Account of type OTHER not supported.");

            default:
                throw new IllegalOperationException("Unsupported account type detected.  Nothing done.");
            }

            //if (extended)
            //{
            //    account = new InterestAccount(name, id, deposit);
            //}
            //else
            //{
            //    account = new SimpleAccount(name, id, deposit);
            //}
            if (account != null)
            {
                try
                {
                    accounts.Add(id, account);

                    if (!Dispatcher.CheckAccess())
                    {
                        Dispatcher.Invoke(AccountDetailsListViewModel.addAction, account.AccountDetails);
                    }
                    else
                    {
                        AccountDetailsListViewModel.addAction.Invoke(account.AccountDetails);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    account = null;
                }
            }
            return(account);
        }