//public async Task<IEnumerable<User>> GetUsers() public async Task <PagedList <User> > GetUsers(UserParams userParams) { var users = _context.Users.Include(p => p.Photos) .OrderByDescending(u => u.LastActive).AsQueryable(); users = users.Where(u => u.Id != userParams.UserId); users = users.Where(u => u.Gender == userParams.Gender); if (userParams.Likers) { var userLikers = await GetUserLikes(userParams.UserId, userParams.Likers); users = users.Where(u => userLikers.Contains(u.Id)); } if (userParams.Likees) { var userLikees = await GetUserLikes(userParams.UserId, userParams.Likers); users = users.Where(u => userLikees.Contains(u.Id)); } if (userParams.MinAge != 18 || userParams.MinAge != 99) { var minDob = DateTime.Today.AddYears(-userParams.MaxAge - 1); var maxDob = DateTime.Today.AddYears(-userParams.MinAge); users = users.Where(u => u.DateOfBirth >= minDob && u.DateOfBirth <= maxDob); } if (!string.IsNullOrEmpty(userParams.OrderBy)) { switch (userParams.OrderBy) { case "created": users = users.OrderByDescending(u => u.Created); break; default: users = users.OrderByDescending(u => u.LastActive); break; } } //var users = await _context.Users.ToListAsync(); //return users; return(await PagedList <User> .CreateAync(users, userParams.PageNumber, userParams.PageSize)); }