public async Task <WithdrawResult> Process(WithdrawCommand 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.Withdraw(command.Amount);
            Debit debit = (Debit)account.GetLastTransaction();

            await accountWriteOnlyRepository.Update(account, debit);

            WithdrawResult result = new WithdrawResult(
                debit,
                account.GetCurrentBalance()
                );

            return(result);
        }
        public async Task <WithdrawResult> Process(WithdrawCommand 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.");
            }

            Debit debit = new Debit(account.Id, command.Amount);

            account.Withdraw(debit);

            await accountWriteOnlyRepository.Update(account, debit);

            TransactionResult transactionResult = resultConverter.Map <TransactionResult>(debit);
            WithdrawResult    result            = new WithdrawResult(
                transactionResult,
                account.GetCurrentBalance().Value
                );

            return(result);
        }
예제 #3
0
        public async Task <WithdrawResult> Handle(WithdrawCommand 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.");
            }

            Debit   debit   = new Debit(new Amount(command.Amount));
            Account account = customer.FindAccount(command.AccountId);

            account.Withdraw(debit);

            await customerWriteOnlyRepository.Update(customer);

            TransactionResult transactionResult = resultConverter.Map <TransactionResult>(debit);
            WithdrawResult    response          = new WithdrawResult(
                transactionResult,
                account.CurrentBalance.Value
                );

            return(response);
        }