public async Task <PagedList <MessageDto> > GetMessagesForUser(MessagePagingParams messagePagingParams) { var query = _context.Messages .OrderByDescending(m => m.MessageSent) .ProjectTo <MessageDto>(_mapper.ConfigurationProvider) .AsQueryable(); query = messagePagingParams.Container switch { "Inbox" => query.Where(m => m.RecipientUsername == messagePagingParams.Username && m.RecipientDeleted == false), "Outbox" => query.Where(m => m.SenderUsername == messagePagingParams.Username && m.SenderDeleted == false), _ => query.Where(m => m.RecipientUsername == messagePagingParams.Username && m.RecipientDeleted == false && m.DateRead == null) }; return(await PagedList <MessageDto> .CreateAsync(query, messagePagingParams.PageNumber, messagePagingParams.PageSize)); }
public async Task <ActionResult <IEnumerable <MessageDto> > > GetMessagesForUser([FromQuery] MessagePagingParams messagePagingParams) { messagePagingParams.Username = User.GetUserName(); var messages = await _unitOfWork.MessageRepository.GetMessagesForUser(messagePagingParams); Response.AddPaginationHeader(messages.CurrentPage, messages.PageSize, messages.TotalCount, messages.TotalPages); return(messages); }