public ActionResult SetPer() { //方式一:简单方式,把旧权限删除掉,然后再把新权限加入 //方式二:原来的所有权限,然后得到新权限,将2个集合相同的删除后,剩下的就是要添加进去的 //采用方式一,首先将这个角色的旧权限删除掉 try { //得到要分配权限的角色Id int roleid = Convert.ToInt32(Request.Form["roleId"]); //删除这个角色的所有权限 OperateContext.Current.BLLSession.IRolePermissionBLL.DelBy(u => u.RoleId == roleid); object perid; //接下来得到所有权限 var listAllPer = OperateContext.Current.BLLSession.IPermissionBLL.GetListBy(u => u.IsDelete == false && u.PerId != 19 && u.PerId != 20 && u.PerId != 21).ToList(); for (int i = 0; i < listAllPer.Count; i++) { string perIdName = listAllPer[i].PerId.ToString(); //只要不为空,则说明你选中了 perid = Request.Form[perIdName]; if (perid != null) { //现在为这个角色添加新的权限到数据库 MODEL.T_RolePermission rp = new MODEL.T_RolePermission(); rp.RoleId = roleid; rp.PerId = Convert.ToInt32(perid); rp.AddTime = DateTime.Now; rp.IsDel = false; OperateContext.Current.BLLSession.IRolePermissionBLL.Add(rp); } } } catch (Exception ex) { return(RedirectToAction("RoleIndex")); } return(RedirectToAction("RoleIndex")); }
public ActionResult SetPer() { //方式一:简单方式,把旧权限删除掉,然后再把新权限加入 //方式二:原来的所有权限,然后得到新权限,将2个集合相同的删除后,剩下的就是要添加进去的 //采用方式一,首先将这个角色的旧权限删除掉 try { //得到要分配权限的角色Id int roleid = Convert.ToInt32(Request.Form["roleId"]); //删除这个角色的所有权限 OperateContext.Current.BLLSession.IRolePermissionBLL.DelBy(u => u.RoleId == roleid); object perid; //接下来得到所有权限 var listAllPer = OperateContext.Current.BLLSession.IPermissionBLL.GetListBy(u =>u.IsDelete == false && u.PerId != 19 && u.PerId != 20 && u.PerId != 21).ToList(); for (int i = 0; i < listAllPer.Count; i++) { string perIdName = listAllPer[i].PerId.ToString(); //只要不为空,则说明你选中了 perid = Request.Form[perIdName]; if (perid!=null) { //现在为这个角色添加新的权限到数据库 MODEL.T_RolePermission rp = new MODEL.T_RolePermission(); rp.RoleId = roleid; rp.PerId = Convert.ToInt32(perid); rp.AddTime = DateTime.Now; rp.IsDel = false; OperateContext.Current.BLLSession.IRolePermissionBLL.Add(rp); } } } catch(Exception ex) { return RedirectToAction("RoleIndex"); } return RedirectToAction("RoleIndex"); }