コード例 #1
0
        public async Task <IActionResult> GetAllUsers([FromQuery] UserRequestParametersDto req)
        {
            // retrieve all the users from the database
            var foundUsers = await _userRepository.GetAllAsync(req);

            // map and return the users
            var listToReturn = _mapper.Map <IEnumerable <ViewUserDto> >(foundUsers);

            return(Ok(listToReturn));
        }
コード例 #2
0
        /// <summary>
        /// Gets all users in the database in a paged order
        /// </summary>
        /// <param name="req">Filtering and searching parameters</param>
        public async Task <IEnumerable <User> > GetAllAsync(UserRequestParametersDto req)
        {
            var query = this._context.Users.AsQueryable().AsNoTracking();

            if (!string.IsNullOrEmpty(req.FilterByRole))
            {
                query = query.Where(x => x.Role.ToLower() == req.FilterByRole.ToLower());
            }
            if (!string.IsNullOrEmpty(req.SearchByEmail))
            {
                query = query.Where(x => x.Email.ToLower().Contains(req.SearchByEmail.ToLower()));
            }
            if (!string.IsNullOrEmpty(req.SearchByUsername))
            {
                query = query.Where(x => x.Username.ToLower().Contains(req.SearchByUsername.ToLower()));
            }
            return(await PaginatedList <User> .CreateAsync(query, req.Page, req.PageSize));
        }