public void WithdrawFrom(string accountNumber, decimal amount, string currency) { if (amount < 0) { throw new InvalidWithDrawalException("Amount cannot be less than 0"); } var bankAccount = _bankAccountStore.GetByAccountNumber(accountNumber); if (bankAccount == null) { throw new AccountNotFoundException(accountNumber); } if (!_accountAuthorisation.RequestForWithdrawal(bankAccount)) { throw new AuthorisationFailedException(); } if ((bankAccount.Balance - amount) < 0) { throw new InsufficientBalanceException(); } bankAccount.Withdraw(amount, currency); }
public void Transfer(decimal amount, string currency, string sourceAccountNumber, string destinationAccountNumber) { if (amount < 0) { throw new InvalidTransferException("Amount cannot be less than 0"); } var sourceAccount = _bankAccountStore.GetByAccountNumber(sourceAccountNumber); if (sourceAccount == null) { throw new AccountNotFoundException(sourceAccountNumber); } var destinationAccount = _bankAccountStore.GetByAccountNumber(destinationAccountNumber); if (destinationAccount == null) { throw new AccountNotFoundException(destinationAccountNumber); } if (!_accountAuthorisation.RequestForWithdrawal(sourceAccount)) { throw new AuthorisationFailedException(); } if ((sourceAccount.Balance - amount) < 0) { throw new InsufficientBalanceException(); } sourceAccount.Withdraw(amount, currency); destinationAccount.Deposit(amount, currency); }