Exemplo n.º 1
0
        public void Transfer(decimal amount, string fromAccountNumber, string toAccountNumber)
        {
            ITransactAccount account = Repository.GetAccount(fromAccountNumber);

            if (account == null)
            {
                throw new KeyNotFoundException($"Account number {account} does not exist.");
            }
            ITransactAccount toAccount = Repository.GetAccount(toAccountNumber);

            if (toAccount == null)
            {
                throw new KeyNotFoundException($"Account number {toAccount} does not exist.");
            }
            if (!(account is ITransactCashOutAccount))
            {
                throw new InvalidOperationException("Invalid from account type for Transfer.");
            }

            ITransactCashOutAccount fromAccount = (ITransactCashOutAccount)account;

            fromAccount.MoveCashOut(amount);
            toAccount.MoveCashIn(amount);
            Repository.SaveAccount(fromAccount);
            Repository.SaveAccount(toAccount);
            Console.WriteLine($"Successful transfer of {amount:C} from {fromAccount.Name} ({fromAccount.AccountNumber}) to {toAccount.Name} ({toAccount.AccountNumber})");
        }
Exemplo n.º 2
0
        public void Deposit(decimal amount, string toAccountNumber)
        {
            ITransactAccount toAccount = Repository.GetAccount(toAccountNumber);

            if (toAccount == null)
            {
                throw new KeyNotFoundException($"Account number {toAccountNumber} does not exist.");
            }

            toAccount.MoveCashIn(amount);
            Repository.SaveAccount(toAccount);
            Console.WriteLine($"Successful deposit of {amount:C} to {toAccount.Name} ({toAccount.AccountNumber})");
        }