/// <summary> /// 获取该用户组的角色 /// </summary> /// <param name="id"></param> /// <param name="page"></param> /// <param name="size"></param> /// <param name="kw"></param> /// <returns></returns> public ActionResult MyRoles(int id, int page = 1, int size = 10, string kw = "") { Expression <Func <Role, bool> > where; Expression <Func <Role, bool> > where2; if (!string.IsNullOrEmpty(kw)) { where = u => u.UserGroupPermission.All(c => c.UserGroupId != id) && u.RoleName.Contains(kw); where2 = u => u.UserGroupPermission.Any(c => c.UserGroupId == id) && u.RoleName.Contains(kw); } else { where = u => u.UserGroupPermission.All(c => c.UserGroupId != id); where2 = u => u.UserGroupPermission.Any(c => c.UserGroupId == id); } List <RoleOutputDto> not = RoleBll.LoadPageEntities <int, RoleOutputDto>(page, size, out int total1, where, u => u.Id, false).ToList(); //不属于该应用 List <Role> list = RoleBll.LoadPageEntities(page, size, out int total2, where2, u => u.Id, false).ToList(); //属于该应用 List <RoleOutputDto> my = new List <RoleOutputDto>(); foreach (var p in list) { //判断有没有临时权限 RoleOutputDto per = p.Mapper <RoleOutputDto>(); per.HasRole = p.UserGroupPermission.Any(u => u.UserGroupId.Equals(id) && u.RoleId == p.Id && u.HasRole); my.Add(per); } return(PageResult(new { my, not }, size, total1 >= total2 ? total1 : total2)); }
/// <summary> /// 获取该应用的角色 /// </summary> /// <param name="id"></param> /// <param name="page"></param> /// <param name="size"></param> /// <param name="kw"></param> /// <returns></returns> public ActionResult MyRoles(int id, int page = 1, int size = 10, string kw = "") { Expression <Func <Role, bool> > where; Expression <Func <Role, bool> > where2; if (!string.IsNullOrEmpty(kw)) { where = u => u.ClientApp.All(c => c.Id != id) && u.RoleName.Contains(kw); where2 = u => u.ClientApp.Any(c => c.Id == id) && u.RoleName.Contains(kw); } else { where = u => u.ClientApp.All(c => c.Id != id); where2 = u => u.ClientApp.Any(c => c.Id == id); } List <RoleOutputDto> not = RoleBll.LoadPageEntities <int, RoleOutputDto>(page, size, out int total1, where, u => u.Id, false).ToList(); //不属于该应用 List <RoleOutputDto> my = RoleBll.LoadPageEntities <int, RoleOutputDto>(page, size, out int total2, where2, u => u.Id, false).ToList(); //属于该应用 return(PageResult(new { my, not }, size, total1 >= total2 ? total1 : total2)); }