/// <summary> /// 获取角色及关联一览 /// </summary> /// <param name="rolePageParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <PageResponse <RoleListDto> > RoleListAsync(RolePageParam rolePageParam, UserCacheBo currentUser) { CloseTracking(); Expression <Func <SysRole, bool> > roleExpression = s => !s.Deleted && s.TenantId == currentUser.TenantId; if (!rolePageParam.RoleName.IsNullOrEmpty()) { roleExpression = roleExpression.And(c => c.RoleName.Contains(rolePageParam.RoleName)); } var tempQueryable = CurrentDbContext.SysRoles.Where(roleExpression); if (currentUser.CreatedBy > 0) { // 非管理员不看系统创建的角色 tempQueryable = tempQueryable.Where(c => c.CreatedBy > 0); } var resultQueryable = from sysRole in tempQueryable select new RoleListDto() { RoleId = sysRole.RoleId.ToString(), RoleDesc = sysRole.RoleDesc, RoleName = sysRole.RoleName, NickNames = from userRole in CurrentDbContext.SysUserRoleRelations join sysUser in CurrentDbContext.SysUsers on userRole.UserId equals sysUser.UserId where userRole.RoleId == sysRole.RoleId && !userRole.Deleted && userRole.TenantId == currentUser.TenantId && userRole.State == 1 && sysUser.State == 1 && sysUser.TenantId == currentUser.TenantId select sysUser.NickName }; var result = await LoadPageEntitiesAsync(resultQueryable, rolePageParam.CurrentPage, rolePageParam.PageSize, false, c => c.RoleId); return(result); }
/// <summary> /// 角色分页查询 /// 贪婪加载 /// Include/IncludeMany /// </summary> /// <returns></returns> public async Task <PageListBase <RoleVO> > GetRolePageAsync(RolePageParam param) { #region 贪婪加载 Include/IncludeMany var list = await _roleRep.Select .IncludeMany(x => x.UserRoles, next => next.Include(ur => ur.User).Include(ur => ur.Role)) .WhereIf(!string.IsNullOrWhiteSpace(param.KeyWord), r => r.FullName.Contains(param.KeyWord)) .WhereIf(param.IsDelete != null, x => x.IsDeleted == param.IsDelete) .Count(out var total) .OrderBy(param.OrderBy) .Page(param.PageIndex + 1, param.PageSize) .ToListAsync(true); #endregion return(new PageListBase <RoleVO>(Mapper.Map <List <RoleVO> >(list), total, param.PageIndex + 1, param.PageSize)); }
public async Task <ActionResult> RoleList(RolePageParam param) { var result = await RoleBll.RoleListAsync(param, CurrentUser); return(Succeed(result)); }
public async Task <IActionResult> GetRolePage([FromQuery] RolePageParam param) { return(Ok(await _commonService.GetRolePageAsync(param))); }
/// <summary> /// 获取角色及关联用户一览 /// </summary> /// <param name="rolePageParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <PageResponse <RoleListDto> > RoleListAsync(RolePageParam rolePageParam, UserCacheBo currentUser) { PageResponse <RoleListDto> roleList = await SysRoleDao.RoleListAsync(rolePageParam, currentUser); return(roleList); }