public async Task <IEnumerable <Permission> > GetPermissionByRoleCodesAsync(List <string> roleCodes) { var rpSpec = new FindRolePermissionSpecification(roleCodes); var rp = await rpRepository.ListAsync(rpSpec); var pCodes = rp.Select(x => x.PermissionCode).ToList(); var permSpec = new FindPermissionSpecification(pCodes); var permissions = await permissionRepository.ListAsync(permSpec); return(permissions); }
public async Task <List <Menu> > GetUserMenusAsync(Guid userId, bool includeHideMenu = false) { // 获取当前用户信息 var userSpec = new FindUserSpecification(userId); var userEntity = await _userRepository.FirstOrDefaultAsync(userSpec); if (userEntity == null) { return(new List <Menu>()); } // 获取当前用户对应的角色编码 var userRoleSpec = new FindUserRoleSpecification(userId); var userRoleEntities = await _userRoleRepository.ListAsync(userRoleSpec); var roleCodes = userRoleEntities.Select(x => x.RoleCode).ToList(); // 获取角色对应的权限编码 var rolePermissionSpec = new FindRolePermissionSpecification(roleCodes); var rolePermissionEntities = await _rolePermissionRepository.ListAsync(rolePermissionSpec); var permissionCodes = rolePermissionEntities.Select(x => x.PermissionCode).ToList(); // 获取权限对应的菜单编码 var permissonSpec = new FindPermissionSpecification(permissionCodes); var permissionEntities = await _permissionRepository.ListAsync(permissonSpec); var menuIds = permissionEntities.Select(x => x.MenuGuid); // 获取菜单 var menuSpec = new FindMenuSpecification(menuIds, IsDeleted.No, Status.Normal); var menuEntities = await _menuRepository.ListAsync(menuSpec); if (includeHideMenu) { return(menuEntities.OrderBy(x => x.Sort).ToList()); } else { return(menuEntities.Where(x => x.HideMenu == YesOrNo.No).OrderBy(x => x.Sort).ToList()); } //return ToMenuBO(menuEntities); }