Example #1
0
        public Object PerformTransfer(BankAccountDto originBankAccountDto, BankAccountDto destinationBankAccountDto, Decimal amount)
        {
            try
            {
                BaseResponseDto <BankAccountDto> baseResponseDto = new BaseResponseDto <BankAccountDto>();
                //List<BankAccountDto> bankAccountDto = this.bankAccountRepository.FindByNumber(originBankAccountDto.Number);
                //baseResponseDto.Data = customerDto;

                var originAccount      = bankAccountRepository.FindByNumber(originBankAccountDto.Number);
                var destinationAccount = bankAccountRepository.FindByNumber(destinationBankAccountDto.Number);
                //transferDomainService.PerformTransfer(originAccount, destinationAccount, amount);

                originAccount.Balance      = originAccount.Balance - amount;
                destinationAccount.Balance = destinationAccount.Balance + amount;

                bankAccountRepository.Update(originAccount);
                bankAccountRepository.Update(destinationAccount);

                return(baseResponseDto);
            }
            catch (Exception)
            {
                return(this.getExceptionErrorResponse());
            }
        }
        public void PerformTransfer(BankAccountDto originBankAccountDto, BankAccountDto destinationBankAccountDto, decimal amount)
        {
            var scope = new TransactionScope();

            using (scope)
            {
                var originAccount      = _bankAccountRepository.FindByNumber(originBankAccountDto.Number);
                var destinationAccount = _bankAccountRepository.FindByNumber(destinationBankAccountDto.Number);
                _transferDomainService.PerformTransfer(originAccount, destinationAccount, amount);
                _bankAccountRepository.update(originAccount);
                _bankAccountRepository.update(destinationAccount);
                scope.Complete();
            }
        }