public async Task<UserSearchResponse> SearchUsersAsync(UserSearchRequest request) { request = request ?? new UserSearchRequest(); var result = new UserSearchResponse(); using (var repository = _platformRepository()) { var query = repository.Accounts; if (request.Keyword != null) { query = query.Where(u => u.UserName.Contains(request.Keyword)); } if(!string.IsNullOrEmpty(request.MemberId)) { //Find all accounts with specified memberId query = query.Where(u => u.MemberId == request.MemberId); } if (request.AccountTypes != null && request.AccountTypes.Any()) { query = query.Where(x => request.AccountTypes.Contains(x.UserType)); } result.TotalCount = query.Count(); var users = query.OrderBy(x => x.UserName) .Skip(request.SkipCount) .Take(request.TakeCount) .ToArray(); var extendedUsers = new List<ApplicationUserExtended>(); foreach (var user in users) { var extendedUser = await FindByNameAsync(user.UserName, UserDetails.Reduced); if (extendedUser != null) { extendedUsers.Add(extendedUser); } } result.Users = extendedUsers.ToArray(); return result; } }
public async Task<UserSearchResponse> SearchUsersAsync(UserSearchRequest request) { request = request ?? new UserSearchRequest(); var result = new UserSearchResponse(); var query = _userManager.Users; if (request.Keyword != null) { query = query.Where(u => u.UserName.Contains(request.Keyword)); } result.TotalCount = query.Count(); var users = query.OrderBy(x => x.UserName) .Skip(request.SkipCount) .Take(request.TakeCount) .ToArray(); var extendedUsers = new List<ApplicationUserExtended>(); foreach (var user in users) { var extendedUser = await FindByNameAsync(user.UserName, UserDetails.Reduced); extendedUsers.Add(extendedUser); } result.Users = extendedUsers.ToArray(); return result; }