public async Task <PagedListResponse <RecipientDto> > Handle(MessageRecipientListQuery request, CancellationToken cancellationToken) { var currentUserId = identityService.GetCurrentUserId(); var totalCount = await context.Users.CountAsync(cancellationToken) + await context.RecipientGroups.CountAsync(x => x.UserId == currentUserId, cancellationToken); var responses = new List <RecipientDto>(); if (totalCount > request.PageIndex * request.PageSize) { responses = await context.Users.Select(x => new RecipientDto { Id = x.Id, Name = x.Name, Type = RecipientDto.RecipientType.User }).Concat(context.RecipientGroups.Select(x => new RecipientDto { Id = x.Id, Name = x.Name, Type = RecipientDto.RecipientType.Group })) .Where(x => string.IsNullOrEmpty(request.SearchText) || x.Name.ToLower().Contains(request.SearchText)) .OrderBy(x => x.Name) .Skip(request.PageIndex * request.PageSize) .Take(request.PageSize) .ToListAsync(cancellationToken); } return(new PagedListResponse <RecipientDto> { Items = responses, PageIndex = request.PageIndex, PageSize = request.PageSize, TotalCount = totalCount }); }
public Task<PagedListResponse<RecipientDto>> ListRecipients([FromQuery] MessageRecipientListQuery query, CancellationToken cancellationToken) { return mediator.Send(query, cancellationToken); }