public async Task <PaginatedWrapperDto <List <Comment> > > FindPaginatedByPollId(Guid pollId, int page) { var skip = (page - 1) * PageSize; var pageCount = (double)_context.Comments.Count() / PageSize; var paginatedWrapper = new PaginatedWrapperDto <List <Comment> > { CurrentPage = page, PageCount = (int)Math.Ceiling(pageCount), AvailableRows = _context.Comments.Count(c => c.Poll.Id == pollId), Data = await _context.Comments .Where(c => c.Poll.Id == pollId) .OrderByDescending(c => c.CreatedAt) .Skip(skip) .Take(PageSize) .ToListAsync() }; return(paginatedWrapper); }
public async Task <PaginatedWrapperDto <List <Comment> > > FindByUsernamePaginated(string username, int page) { var skip = (page - 1) * PageSize; var pageCount = (double)_context.Comments.Count() / PageSize; var paginatedWrapper = new PaginatedWrapperDto <List <Comment> > { CurrentPage = page, PageCount = (int)Math.Ceiling(pageCount), AvailableRows = _context.Comments.Count(c => c.Author.UserName == username), Data = await _context.Comments .Where(c => c.Author.UserName == username) .Include(c => c.Poll) .OrderByDescending(c => c.CreatedAt) .Skip(skip) .Take(PageSize) .ToListAsync() }; return(paginatedWrapper); }