Beispiel #1
0
        private async Task LoanExpireTaxWorker(ILoanRepository repository, CancellationToken cancellationToken)
        {
            try{
                var loans = await repository.GetExpiredLoan(cancellationToken);

                foreach (var loan in loans)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }
                    try{
                        _logger.LogInformation($"LoanExpireTaxWorker: Start process loan: {loan.Id}");
                        _loanTaxProcessor.ProcessExpireLoan(loan);
                        await _loanProcessor.Process(loan, cancellationToken);

                        await repository.Save(loan, cancellationToken);

                        _logger.LogInformation($"LoanExpireTaxWorker: End process loan: {loan.Id}");
                    }
                    catch (Exception e) {
                        _logger.LogError(e, $"LoanExpireTaxWorker: {e.Message}");
                    }
                }
            }
            catch (Exception e) {
                _logger.LogError(e, $"LoanExpireTaxWorker: {e.Message}");
            }
        }
        public async Task <IActionResult> ProcessLoan(
            [FromServices] ILoanRepository repository,
            [FromRoute] Guid id,
            [FromServices] LoanProcessor processor,
            [FromServices] IQueryProcessor queryProcessor,
            CancellationToken cancellationToken)
        {
            var loan = await repository.Get(id, cancellationToken);

            if (loan == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.LoanNotFound, $"Loan {id} not found");
            }

            try{
                await processor.Process(loan, cancellationToken);

                await repository.Save(loan, cancellationToken);
            }
            catch (InvalidOperationException) {
                throw new ApiException(HttpStatusCode.Conflict, ErrorCodes.IncorrectOperation, $"Incorrect loan state");
            }

            return(Ok(await queryProcessor.Process <LoanViewQuery, LoanView>(new LoanViewQuery(id), cancellationToken)));
        }
Beispiel #3
0
        public async Task Handle(
            LoanOperationCreated message,
            CancellationToken cancellationToken)
        {
            _logger.LogInformation($"LoanOperationCreated for loan {message.LoanId} has received");
            var loan = await _loanRepository.Get(message.LoanId, cancellationToken);

            if (loan == null)
            {
                throw new InvalidOperationException($"Loan: {message.LoanId} not found");
            }
            await _loanProcessor.Process(loan, cancellationToken);

            await _loanRepository.Save(loan, cancellationToken);
        }