public async Task <IActionResult> GetAllAgreementsByMemberId([FromRoute] int memberId) { var query = new GetAllAgreementsByMemberIdQuery(memberId); var result = await _mediator.Send(query); return(Ok(result)); }
public async Task <List <AgreementDto> > Handle(GetAllAgreementsByMemberIdQuery request, CancellationToken cancellationToken) { var agreementsList = await _dbContext .Agreements.Where(m => m.MemberId == request.MemberId) .OrderByDescending(a => a.StartingDate) .ToListAsync(cancellationToken); if (agreementsList is null) { throw new NullReferenceException($"Agreements for member [MembershipId: {request.MemberId}] not found"); } return(agreementsList.Select(agreement => agreement.Adapt <AgreementDto>()).ToList()); }
public async Task <List <AgreementDto> > Handle(GetAllAgreementsByMemberIdQuery request, CancellationToken cancellationToken) { var agreementsList = await _dbContext .Agreements .Where(m => m.MemberId == request.MemberId) .ToListAsync(cancellationToken); if (agreementsList is null) { throw new NullReferenceException($"Agreements for member [MemberId: {request.MemberId}] not found"); } agreementsList = await AgreementPaymentValidator .IsPaidAsync(_dbContext, agreementsList, cancellationToken); return(agreementsList.Select(agreement => agreement.Adapt <AgreementDto>()).ToList()); }