public ActionResult ConfigAuth(int id) { RoleAuthModel model = new RoleAuthModel(); IPlatformRoleBLL platformRoleBll = BLLFactory <IPlatformRoleBLL> .GetBLL("PlatformRoleBLL"); //获取要分配角色的平台角色 T_PlatformRole role = platformRoleBll.GetEntity(m => m.Id == id); IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL"); //获取所有的菜单 var menuList = menuBll.GetList(m => m.MenuFlag == ConstantParam.MENU_LEFT && m.IsPlatform == ConstantParam.USER_TYPE_PLATFORM && m.ParentId == null).OrderBy(m => m.Order).ToList(); //Model赋值菜单列表 model.MenuList = menuList; //Model赋值要分配角色的平台角色 model.Role = new RoleModel() { RoleId = role.Id, RoleName = role.RoleName, RoleMemo = role.RoleMemo }; //获取该角色已经有的权限ID集合 model.ActionIds = role.PlatformRoleActions.Select(m => m.ActionId).ToList(); return(View(model)); }
public RoleAuthModel GetSelectRole(int roleid) { Func <URole, IEnumerable <SelectListItem> > sa = c => { List <SelectListItem> selectroles = this.Authorises.FindAll().Select(s => new SelectListItem { Text = s.Name, Value = s.AuthoriseID.ToString(), Selected = false }).ToList(); foreach (var item in selectroles) { foreach (var sr in c.Authorizes) { if (item.Value == sr.AuthoriseID.ToString()) { item.Selected = true; break; } } } return(selectroles); }; var r = this.Roles.GetById(roleid); var ra = new RoleAuthModel { RoleID = r.RoleID, Name = r.Name, Description = r.Description, Authorises = sa(r) }; return(ra); }
public ActionResult Auth(string ID) { var rolePages = SysService.GetRolePages(ID); RoleAuthModel model = new RoleAuthModel { RoleID = ID, Pages = new List <AuthPageModel>() }; foreach (var g in AppConfig.Current.PageGroups) { foreach (var p in g.Pages.Where(w => w.IsEnable)) { model.Pages.Add(new AuthPageModel { PageID = p.PageID, Title = p.Title, Actions = p.Config.Actions.Where(a => a.IsEnable).GroupBy(a => a.Title) .Select(m => new AuthActionModel { ActionTitle = m.Key, ActionValue = m.First().ActionValue, IsSelected = rolePages.FirstOrDefault(f => f.PageID.Equals(p.PageID) && (f.ActionValue & m.First().ActionValue) == m.First().ActionValue) != null }).ToList() }); } } return(View(model)); }
public ActionResult Create() { RoleAuthModel model = new RoleAuthModel { RoleID = "", Pages = new List <AuthPageModel>() }; model.Titles = new List <string>(); foreach (var g in AppConfig.Current.PageGroups) { model.Titles.Add(g.Name); foreach (var p in g.Pages.Where(w => w.IsEnable)) { model.Pages.Add(new AuthPageModel { PageID = p.PageID, Title = p.Title, Name = g.Name, Actions = p.Config.Actions.Where(a => a.IsEnable).GroupBy(a => a.Title) .Select(m => new AuthActionModel { ActionTitle = m.Key, ActionValue = m.First().ActionValue, IsSelected = false }).ToList() }); } } return(View(model)); }
public ActionResult AddRole() { RoleAuthModel ram = new RoleAuthModel { Authorises = this.webservice.GetAuthorises() }; return(View(ram)); }
public ActionResult ViewAuth(int id) { RoleAuthModel model = new RoleAuthModel(); IPlatformRoleBLL platformRoleBll = BLLFactory <IPlatformRoleBLL> .GetBLL("PlatformRoleBLL"); //获取要查看权限的平台角色 T_PlatformRole role = platformRoleBll.GetEntity(m => m.Id == id); //赋值 要查看权限的平台角色 model.Role = new RoleModel() { RoleId = role.Id, RoleName = role.RoleName, RoleMemo = role.RoleMemo }; //如果是普通角色 if (role.IsSystem == ConstantParam.USER_ROLE_DEFAULT) { //赋值 该角色所有的权限ID集合 model.ActionIds = role.PlatformRoleActions.Select(m => m.ActionId).ToList(); //Model赋值 该角色所关联的非重复菜单 var roleMenuList = role.PlatformRoleActions.Select(m => m.Action.Menu).Distinct().OrderBy(m => m.Order).ToList(); //新定义展示Model树形菜单 var menuList = new List <M_Menu>(); foreach (var menu in roleMenuList) { if (menu.ParentId != null) { if (!menuList.Contains(menu.ParentMenu)) { menuList.Add(menu.ParentMenu); } } menuList.Add(menu); } model.MenuList = menuList; } else { IActionBLL actionBll = BLLFactory <IActionBLL> .GetBLL("ActionBLL"); //赋值 所有的平台权限 model.ActionIds = actionBll.GetList(a => a.Menu.IsPlatform == ConstantParam.USER_TYPE_PLATFORM).Select(a => a.Id).ToList(); IMenuBLL menuBll = BLLFactory <IMenuBLL> .GetBLL("MenuBLL"); //Model赋值 所有的平台菜单 model.MenuList = menuBll.GetList(m => m.IsPlatform == ConstantParam.USER_TYPE_PLATFORM).ToList(); } return(View(model)); }
public ActionResult Edit(string ID) { var model = SysService.GetRole(ID); var rolePages = SysService.GetRolePages(ID); RoleAuthModel pagemodel = new RoleAuthModel { RoleID = ID, Name = model.Name, Description = model.Description, Pages = new List <AuthPageModel>() }; pagemodel.DataFilter = null; pagemodel.Titles = new List <string>(); foreach (var g in AppConfig.Current.PageGroups) { pagemodel.Titles.Add(g.Name); foreach (var p in g.Pages.Where(w => w.IsEnable)) { pagemodel.Pages.Add(new AuthPageModel { PageID = p.PageID, Title = p.Title, Name = g.Name, Actions = p.Config.Actions.Where(a => a.IsEnable).GroupBy(a => a.Title) .Select(m => new AuthActionModel { ActionTitle = m.Key, ActionValue = m.First().ActionValue, IsSelected = rolePages.FirstOrDefault(f => f.PageID.Equals(p.PageID) && (f.ActionValue & m.First().ActionValue) == m.First().ActionValue) != null }).ToList() }); } } var companyids = (from rp in rolePages where rp.PageID.Equals("P01001") select rp.DataFilter.ToString()).ToArray(); var deptids = (from rp in rolePages where rp.PageID.Equals("P01002") select rp.DataFilter.ToString()).ToArray();; var bankids = (from rp in rolePages where rp.PageID.Equals("P01017") select rp.DataFilter.ToString()).ToArray(); foreach (var companyid in companyids) { pagemodel.DataFilter += companyid; } pagemodel.DataFilter += ":"; foreach (var deptid in deptids) { pagemodel.DataFilter += deptid; } pagemodel.DataFilter += ":"; foreach (var bankid in bankids) { pagemodel.DataFilter += bankid; } return(View(pagemodel)); }
public ActionResult RoleEdit(RoleAuthModel ram, string[] auth) { if (auth != null) { this.webservice.updateRole(ram, auth); ModelState.AddModelError("", "修改成功!"); ram.Authorises = this.webservice.GetSelectAuth(auth); } else { ModelState.AddModelError("", "请选择权限!"); ram.Authorises = this.webservice.GetAuthorises(); } return(View(ram)); }
public void addRole(RoleAuthModel ram, string[] auth) { var r = new URole { Name = ram.Name, Description = ram.Description, }; this.Roles.Insert(r); foreach (var item in auth) { this.RoleAuthorises.Insert(new URoleAuthorise { RoleID = r.RoleID, AuthoriseID = int.Parse(item) }); } }
public ActionResult AddRole(RoleAuthModel ram, string[] auth) { if (this.webservice.RoleExit(ram.Name)) { ModelState.AddModelError("Name", "角色名已存在"); } else if (auth != null) { this.webservice.addRole(ram, auth); ModelState.AddModelError("", "角色添加成功!"); } else { ModelState.AddModelError("", "请选择权限!"); } ram.Authorises = this.webservice.GetAuthorises(); return(View(ram)); }
/// <summary> /// 更新角色 /// </summary> /// <param name="r"></param> /// <param name="auth"></param> public void updateRole(RoleAuthModel ram, string[] auth) { //var r = this.Roles.Find(n => n.RoleID == ram.RoleID); var r = this.Roles.GetById(ram.RoleID); r.Name = ram.Name; r.Description = ram.Description; this.Roles.Update(r); var oldauth = r.Authorizes.ToList(); var newauth = auth.ToList(); for (int i = 0; i < oldauth.Count(); i++) { for (int j = 0; j < newauth.Count(); j++) { if (oldauth[i].AuthoriseID.ToString() == newauth[j]) { oldauth.Remove(oldauth[i]); newauth.Remove(newauth[j]); } } } if (oldauth.Count > 0) { foreach (var item in oldauth) { this.RoleAuthorises.Delete(item.RelationID); } } if (newauth.Count > 0) { foreach (var item in newauth) { this.RoleAuthorises.Insert(new URoleAuthorise { AuthoriseID = int.Parse(item), RoleID = r.RoleID }); } } }