public async Task <IActionResult> GetUsers([FromQuery] UserForFilterDto filterDto) { var users = await _service.GetUsers(base.GetUserIdFromToken(), filterDto); Response.AddPagination(users.CurrentPage, users.PageSize, users.TotalCount, users.TotalPages); return(Ok(_mapper.To <IEnumerable <UserForListDto> >(users))); }
public async Task <PagedResult <User> > GetUsers(int userId, UserForFilterDto filter) { var query = _context.Users .Include(p => p.Photos) .OrderByDescending(u => u.LastActive) .AsQueryable(); query = query.Where(u => u.Id != userId); if (!string.IsNullOrWhiteSpace(filter.Gender)) { query = query.Where(u => u.Gender == filter.Gender); } if (filter.MinAge != 18 || filter.MaxAge != 99) { var minDateOfBirth = DateTime.Today.AddYears(-filter.MaxAge - 1); var maxDateOfBirth = DateTime.Today.AddYears(-filter.MinAge); query = query.Where(u => u.DateOfBirth >= minDateOfBirth && u.DateOfBirth <= maxDateOfBirth); } if (!string.IsNullOrWhiteSpace(filter.OrderBy)) { switch (filter.OrderBy.ToLower()) { case "created": query = query.OrderByDescending(u => u.Created); break; default: query = query.OrderByDescending(u => u.LastActive); break; } } return(await this.PagedFilterAsync(query, filter.PageNumber, filter.PageSize)); }
public Task <PagedResult <User> > GetUsers(int userId, UserForFilterDto filter) => _unitOfWork.Users.GetUsers(userId, filter);