public async Task <PagedModel <SysUserDto> > SearchUsers(UserSearchModel searchModel) { Expression <Func <SysUser, bool> > whereCondition = x => x.Status > 0; if (!string.IsNullOrWhiteSpace(searchModel.Account)) { whereCondition = whereCondition.And(x => x.Account.Contains(searchModel.Account)); } if (!string.IsNullOrWhiteSpace(searchModel.Name)) { whereCondition = whereCondition.And(x => x.Name.Contains(searchModel.Name)); } var pagedModel = await _userRepository.PagedAsync(searchModel.PageIndex, searchModel.PageSize, whereCondition, x => x.ID); var result = _mapper.Map <PagedModel <SysUserDto> >(pagedModel); if (result.Count > 0) { var depts = await _deptRepository.SelectAsync(x => true); var roles = await _roleRepository.SelectAsync(x => true); foreach (var user in result.Data) { user.DeptName = depts.FirstOrDefault(x => x.ID == user.DeptId)?.FullName; var roleIds = string.IsNullOrWhiteSpace(user.RoleId) ? new List <long>() : user.RoleId.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)); user.RoleName = string.Join(',', roles.Where(x => roleIds.Contains(x.ID)).Select(x => x.Name)); } } return(result); }
public async Task <List <DeptNode> > GetDeptList() { List <DeptNode> result = new List <DeptNode>(); var depts = await _deptRepository.SelectAsync(x => true); if (depts.Any()) { var deptNodes = _mapper.Map <List <DeptNode> >(depts); var dictDepts = deptNodes.ToDictionary(x => x.ID); foreach (var pair in dictDepts) { var currentDept = pair.Value; var parentDept = deptNodes.FirstOrDefault(x => x.ID == currentDept.Pid); if (parentDept != null) { parentDept.Children.Add(currentDept); } else { result.Add(currentDept); } } } return(result); }