示例#1
0
        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;
            }
        }
示例#2
0
 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");
 }