public Transaction Transfer(Account accountToDebit, Account accountToCredit, double valueToTransfer) { ValidateTransfer(accountToDebit, accountToCredit, valueToTransfer); using (var transScope = new TransactionScope()) { accountToDebit.Debit(valueToTransfer); accountToCredit.Credit(valueToTransfer); var transaction = new Transaction(accountToDebit, accountToCredit, valueToTransfer); AccountRepository.Save(accountToDebit); AccountRepository.Save(accountToCredit); BankStatementRepository.RegisterTransaction(transaction); transScope.Complete(); return transaction; } }
private static void ValidateTransfer(Account accountToDebit, Account accountToCredit, double valueToTransfer) { if (!accountToDebit.IsPossibleDebit()) throw new Exception("This account cannot be debit"); if (!accountToCredit.IsPossibleCredit()) throw new Exception("This account cannot be credit"); if (!valueToTransfer.ValueIsValidToTransfer()) throw new Exception("The value should be greater than zero"); }