Esempio n. 1
0
        public async Task <IActionResult> GetAllInstallmentsByAgreementId([FromRoute] int agreementId)
        {
            var query  = new GetAllInstallmentsByAgreementIdQuery(agreementId);
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
        public async Task <List <InstallmentDto> > Handle(GetAllInstallmentsByAgreementIdQuery request,
                                                          CancellationToken cancellationToken)
        {
            var installmentsList = await _dbContext
                                   .Installments
                                   .Where(m => m.AgreementId == request.AgreementId)
                                   .OrderBy(m => m.StartingDate)
                                   .ToListAsync(cancellationToken);

            if (installmentsList is null)
            {
                throw new NullReferenceException(
                          $"Installments for agreement [agreementId: {request.AgreementId}] not found");
            }

            return(installmentsList.Select(installment => installment.Adapt <InstallmentDto>()).ToList());
        }