Exemplo n.º 1
0
        public async Task <WithdrawOutput> Execute(Guid accountId, Amount amount)
        {
            Account account = await _accountReadOnlyRepository.Get(accountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {accountId} does not exists or is already closed.");
            }

            account.Withdraw(amount);
            Debit debit = (Debit)account.GetLastTransaction();

            await _accountWriteOnlyRepository.Update(account, debit);

            WithdrawOutput output = new WithdrawOutput(
                debit,
                account.GetCurrentBalance()
                );

            return(output);
        }
Exemplo n.º 2
0
        public async Task Process(WithdrawInput input)
        {
            Account account = await accountReadOnlyRepository.Get(input.AccountId);

            if (account == null)
            {
                throw new AccountNotFoundException($"The account {input.AccountId} does not exists or is already closed.");
            }

            Debit debit = new Debit(new Amount(input.Amount));

            account.Withdraw(debit);

            await accountWriteOnlyRepository.Update(account);

            TransactionOutput transactionOutput = outputConverter.Map <TransactionOutput>(debit);
            WithdrawOutput    output            = new WithdrawOutput(
                transactionOutput,
                account.GetCurrentBalance().Value
                );

            outputBoundary.Populate(output);
        }