public IActionResult List([FromQuery] int pageIndex, int pageSize, string keywords) { var roles = _roleManager.Roles; if (!string.IsNullOrWhiteSpace(keywords)) { roles = roles.Where(_ => _.Name.Contains(keywords)); } int total = roles.Count(); int skip = (pageIndex - 1) * pageSize; roles = roles.Skip(skip).Take(pageSize); return(EasyResult.PagedList(roles, total)); }
public async Task <IActionResult> GetUserList([FromQuery] int pageIndex, int pageSize, string keywords) { var users = _userManager.Users; if (!string.IsNullOrWhiteSpace(keywords)) { users = users.Where(_ => _.UserName.Contains(keywords, StringComparison.CurrentCultureIgnoreCase)); } int total = users.Count(); int skip = (pageIndex - 1) * pageSize; var pagedUsers = users.Skip(skip).Take(pageSize).ToList(); var result = new List <UserDto>(); foreach (var user in pagedUsers) { var claims = await _userManager.GetClaimsAsync(user); var isActive = claims.FirstOrDefault(_ => _.Type == "isactive")?.Value == null ? false : bool.Parse(claims.FirstOrDefault(_ => _.Type == "isactive").Value); var role = string.IsNullOrWhiteSpace(claims.FirstOrDefault(_ => _.Type == "role")?.Value) ? "游客" : claims.FirstOrDefault(_ => _.Type == "role")?.Value; result.Add(new UserDto { Id = user.Id, Mobile = user.PhoneNumber, Email = user.Email, IsActive = isActive, UserName = user.UserName, Role = role }); } return(EasyResult.PagedList(result, total)); }