public void LoadData() { RoleBll BLL = new RoleBll(); //role = BLL.GetById(1); role = BLL.GetById(Convert.ToInt32(Request["id"])); }
public ActionResult AddRole(string id = null) { //如果ID为null 则是添加,否则是修改 if (string.IsNullOrEmpty(id)) { return(View()); } var role = roleBll.GetById(id); return(View(role)); }
/// <summary> /// 移除客户端子系统应用 /// </summary> /// <param name="id">角色id</param> /// <param name="aids">应用id集合</param> /// <returns></returns> public ActionResult RemoveApps(int id, string aids) { string[] ids = aids.Split(','); Role role = RoleBll.GetById(id); if (role is null) { return(ResultData(null, false, "未找到相应的角色信息!")); } List <ClientApp> apps = ClientAppBll.LoadEntities(a => ids.Contains(a.Id.ToString())).ToList(); apps.ForEach(a => role.ClientApp.Remove(a)); bool b = RoleBll.UpdateEntitySaved(role); return(ResultData(null, b, b ? "角色配置完成!" : "角色配置失败!")); }
/// <summary> /// 移除权限 /// </summary> /// <param name="id">角色id</param> /// <param name="pids">权限id集合</param> /// <returns></returns> public ActionResult RemovePermissions(int id, string pids) { string[] ids = pids.Split(','); Role role = RoleBll.GetById(id); if (role is null) { return(ResultData(null, false, "未找到相应的角色信息!")); } List <Permission> permissions = PermissionBll.LoadEntities(p => ids.Contains(p.Id.ToString())).ToList(); permissions.ForEach(p => role.Permission.Remove(p)); bool b = RoleBll.UpdateEntitySaved(role); return(ResultData(null, b, b ? "角色配置完成!" : "角色配置失败!")); }
/// <summary> /// 将用户移除角色 /// </summary> /// <param name="id">角色id</param> /// <param name="uids">用户id集合</param> /// <returns></returns> public ActionResult RemoveUsers(int id, string uids) { string[] ids = uids.Split(','); Role role = RoleBll.GetById(id); if (role is null) { return(ResultData(null, false, "未找到相应的角色信息!")); } List <UserInfo> users = UserInfoBll.LoadEntities(u => ids.Contains(u.Id.ToString())).ToList(); users.ForEach(u => role.UserInfo.Remove(u)); bool b = RoleBll.SaveChanges() > 0; return(ResultData(null, b, b ? "角色配置完成!" : "角色配置失败!")); }
protected void Page_Load(object sender, EventArgs e) { if (Request["roleId"] == null) { LoadData(); } else { role = new RoleModel(); RoleBll BLL = new RoleBll(); role.Id = Convert.ToInt32(Request["roleId"]); role.Name = Request["roleName"]; role.Remark = Request["roleRemark"]; role.UpdateTime = DateTime.Now; int rows = BLL.Update(role); role = BLL.GetById(Convert.ToInt32(Request["roleId"])); Response.Write(rows); } }
/// <summary> /// 添加用户组 /// </summary> /// <param name="id">角色id</param> /// <param name="gids">用户组id集合</param> /// <returns></returns> public ActionResult AddGroups(int id, string gids) { string[] ids = gids.Split(','); Role role = RoleBll.GetById(id); if (role is null) { return(ResultData(null, false, "未找到相应的角色信息!")); } List <UserGroup> groups = UserGroupBll.LoadEntities(g => ids.Contains(g.Id.ToString())).ToList(); groups.ForEach(g => UserGroupRoleBll.AddEntity(new UserGroupRole() { UserGroup = g, Role = role, HasRole = true, RoleId = role.Id, UserGroupId = g.Id })); bool b = UserGroupRoleBll.SaveChanges() > 0; return(ResultData(null, b, b ? "角色配置完成!" : "角色配置失败!")); }
/// <summary> /// 获取角色详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Details(int id) { Role role = RoleBll.GetById(id); if (role != null) { (IQueryable <ClientApp>, IQueryable <UserInfo>, IQueryable <UserGroupRole>, List <Role>, List <Permission>, List <Control>, List <Menu>)details = RoleBll.Details(role); return(ResultData(new { result = role.Mapper <RoleInputDto>(), apps = details.Item1.Mapper <List <ClientAppInputDto> >(), groups_allow = details.Item3.Where(g => g.HasRole).Select(g => g.UserGroup).ToList().Mapper <List <UserGroupInputDto> >(), groups_forbid = details.Item3.Where(g => !g.HasRole).Select(g => g.UserGroup).ToList().Mapper <List <UserGroupInputDto> >(), roles = details.Item4.Mapper <List <RoleInputDto> >(), permissions = details.Item5.Mapper <List <PermissionInputDto> >(), controls = details.Item6.Mapper <List <ControlOutputDto> >(), menus = details.Item7.Mapper <List <MenuOutputDto> >() })); } return(ResultData(null, false, "用角色不存在")); }
/// <summary> /// 添加或修改角色 /// </summary> /// <param name="Id"></param> /// <param name="RoleName">新名字</param> /// <param name="ParentId">父级组</param> /// <param name="appid">appid</param> /// <returns></returns> public ActionResult Save(int Id = 0, string RoleName = "", int?ParentId = null, string appid = "") { ParentId = ParentId == 0 ? null : ParentId; Role role = RoleBll.GetById(Id); if (role != null) { //修改 if (RoleBll.Any(a => a.RoleName.Equals(RoleName) && !a.RoleName.Equals(role.RoleName))) { return(ResultData(null, false, $"{RoleName} 角色已经存在!")); } role.RoleName = RoleName; role.ParentId = ParentId; bool b = RoleBll.UpdateEntitySaved(role); return(ResultData(null, b, b ? "修改成功" : "修改失败!")); } //添加 if (RoleBll.Any(a => a.RoleName.Equals(RoleName))) { return(ResultData(null, false, $"{RoleName} 角色已经存在!")); } role = new Role() { RoleName = RoleName, ParentId = ParentId }; if (!string.IsNullOrEmpty(appid) && ClientAppBll.Any(a => a.AppId.Equals(appid))) { var app = ClientAppBll.GetFirstEntity(a => a.AppId.Equals(appid)); app.Roles.Add(role); bool b = ClientAppBll.UpdateEntitySaved(app); return(ResultData(null, b, b ? "角色添加成功!" : "角色添加失败!")); } role = RoleBll.AddEntitySaved(role); return(role != null?ResultData(role, true, "角色添加成功!") : ResultData(null, false, "角色添加失败!")); }
/// <summary> /// 获取角色详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Get(int id) { RoleOutputDto role = RoleBll.GetById(id).Mapper <RoleOutputDto>(); return(ResultData(role)); }