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