Exemple #1
0
 public async Task Consume(ConsumeAccountCommand command, CancellationToken cancellationToken = default)
 {
     try
     {
         await _accountsCommandHandler.ExecuteAsync(command, cancellationToken);
     }
     catch (Exception ex)
     { throw ex; }
 }
Exemple #2
0
        public async Task ExecuteAsync(ConsumeAccountCommand command, CancellationToken cancellationToken = default)
        {
            try
            {
                // validate command
                ValidateCommand(command);

                // get any account type
                var accounts = await _accountRepository.GetAsync(ac =>
                                                                 ac.Company == command.Company &&
                                                                 ac.CPF == command.CPF &&
                                                                 ac.AccountId == command.AccountId);

                if (!accounts.Any())
                {
                    throw new InvalidOperationException("invalid account.");
                }

                // get the selected account
                var account = accounts.Single();

                // validate account for change
                ValidateAccountForChange(account);

                // consume from balance
                account.Consume(command.Value, command.Location);

                // update selected account
                _accountRepository.Update(account);
                await _accountRepository.SaveChangesAsync(cancellationToken);

                // add the account transaction into the blockchain
                await AddBlockToBlockchain(account);
            }
            catch (Exception ex)
            { throw ex; }
        }