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