public IActionResult GetSearchedUsers([FromQuery] SearchForUsersDto searchForUsersDto) { var userId = User.GetUserId(); var foundUsers = _userDataService.FindUsers(searchForUsersDto, userId); return(Ok(foundUsers)); }
public ICollection <MemberDto> FindUsers(SearchForUsersDto searchForUsersDto, string userId) { var phrases = searchForUsersDto.SearchPhrase.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); var boardId = searchForUsersDto.BoardId; var queriedUsers = new List <User>(); foreach (var phrase in phrases) { if (phrase == phrases[0]) { queriedUsers = _userManager.Users.Include(x => x.Boards) .Where(x => !x.IsProfileAnonymous) .Where(x => x.Id != userId && CheckConditionForSearchingPeople(x, phrase)) .ToList(); } else { queriedUsers = queriedUsers.Where(x => CheckConditionForSearchingPeople(x, phrase)).ToList(); } } var result = queriedUsers.Select(user => PrepareFoundUser(user, boardId)).ToList(); return(result); }