public async Task <DepositResult> Process(DepositCommand command) { Account account = await accountReadOnlyRepository.Get(command.AccountId); if (account == null) { throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed."); } Credit credit = new Credit(new Amount(command.Amount)); account.Deposit(credit); await accountWriteOnlyRepository.Update(account); TransactionResult transactionResult = resultConverter.Map <TransactionResult>(credit); DepositResult result = new DepositResult(transactionResult, account.GetCurrentBalance().Value); return(result); }
public async Task <DepositResult> Handle(DepositCommand command) { Customer customer = await customerReadOnlyRepository.GetByAccount(command.AccountId); if (customer == null) { throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed."); } Credit credit = new Credit(new Amount(command.Amount)); Account account = customer.FindAccount(command.AccountId); account.Deposit(credit); await customerWriteOnlyRepository.Update(customer); TransactionResult transactionResult = resultConverter.Map <TransactionResult>(credit); DepositResult response = new DepositResult(transactionResult, account.CurrentBalance.Value); return(response); }
public async Task <DepositResult> Process(DepositCommand command) { Account account = await accountReadOnlyRepository.Get(command.AccountId); if (account == null) { throw new AccountNotFoundException($"The account {command.AccountId} does not exists or is already closed."); } account.Deposit(command.Amount); Credit credit = (Credit)account.GetLastTransaction(); await accountWriteOnlyRepository.Update( account, credit); DepositResult result = new DepositResult( credit, account.GetCurrentBalance()); return(result); }