1.为用户设置角色

 {
Layout = null;
}
@using OA.Model
<!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SetRoleInfo</title>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
function subForm()
{
$('#form1').submit();
}
function a()
{
alert("a");
}
function afterSubmit(data)
{
window.parent.AfterSubmit(data)
//parent.document.getElementsByTagName("roleFrame")["roleFrame"].AfterSubmit(data);
}
</script>
</head>
<body>
<div>
为用户@{
UserInfo userInfo = ViewBag.UserInfo;
@userInfo.UName
}添加角色
@using (Ajax.BeginForm("AddRole", "UserInfo", new { }, new AjaxOptions() { HttpMethod = "Post", OnSuccess = "afterSubmit" }, new { id = "form1" }))
{
<input type="hidden" name="userId" value="@userInfo.ID"/>
IList<RoleInfo> roleInfoList=ViewBag.RoleInfoList;
IList<int> roleIds=ViewBag.roleIds;
string ckName="ck_"; foreach (RoleInfo role in roleInfoList)
{
string checkName=ckName+role.ID;
if (roleIds.Contains(role.ID))
{
<input type="checkbox" value="@role.ID" name="@checkName" id="@role.ID" checked="checked"/>@role.RoleName<br/>
}
else
{
<input type="checkbox" value="@role.ID" name="@checkName" id="@role.ID" />@role.RoleName<br/>
} }
}
</div>
</body>
</html>

后台代码

  public ActionResult AddRole()
{
int userId = int.Parse(Request["userId"]);
string[] allKeys = Request.Form.AllKeys;
IList<int> roleIdList = new List<int>();
foreach (string k in allKeys)
{
if (k.StartsWith("ck_"))
{
string k1 = k.Replace("ck_", "");
roleIdList.Add(int.Parse(k1));
}
}
string result = userInfoService.SetRole(userId, roleIdList);
return Content(result);
}

2.为用户设置权限

 @{
Layout = null;
}
@using OA.Model
<!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>SetUserActionInfo</title>
<link href="~/Content/themes/default/easyui.css" rel="stylesheet" />
<link href="~/Content/themes/icon.css" rel="stylesheet" />
<link href="~/Content/tableStyle.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/Scripts/easyui-lang-zh_CN.js"></script>
<script src="~/Scripts/jquery.easyui.min.js"></script>
</head>
<body>
<div>
为用户@{
UserInfo user = ViewBag.User as UserInfo;
@user.UName }分配权限
<table>
<tr>
<th>权限编号</th>
<th>权限名称</th>
<th>地址</th>
<th>请求方式</th>
<th>操作</th>
</tr> @{ IList<ActionInfo> actionInfoList = ViewBag.ActionInfoList as IList<ActionInfo>;
IList<R_UserInfo_ActionInfo> userActionList = ViewBag.UserActionList as IList<R_UserInfo_ActionInfo>;
foreach (ActionInfo action in actionInfoList)
{
<tr>
<td>@action.ID</td>
<td>@action.ActionInfoName</td>
<td>@action.Url</td>
<td>@action.HttpMethod</td>
<td>
@{
var result =( from a in userActionList
where a.ActionInfoID == action.ID
select a).ToList();
if (result != null&&result .Count >)
{
R_UserInfo_ActionInfo rua = result.FirstOrDefault();
if (rua.IsPass)
{
<label for="rdo_@action.ID">允许</label><input type="radio" class="radiosecelction" checked="checked" name="rdoY_@action.ID" id="rdo_@action.ID" ids="@action.ID" value="" /> <label for="rdoY_@action.ID">禁止</label><input type="radio" class="radiosecelction" name="rdoY_@action.ID" id="rdoY_@action.ID" ids="@action.ID" value="" />
<input type="button" value="清除" class="clearbtn" ids="@action.ID" />
}
else
{
<label for="rdo_@action.ID">允许</label><input type="radio" name="rdoY_@action.ID" class="radiosecelction" id="rdo_@action.ID" value="" ids="@action.ID" /> <label for="rdoY_@action.ID">禁止</label><input type="radio" checked="checked" class="radiosecelction" name="rdoY_@action.ID" id="rdoY_@action.ID" value="" ids="@action.ID" />
<input type="button" value="清除" class="clearbtn" ids="@action.ID" />
}
}
else
{
<label for="rdo_@action.ID">允许</label><input type="radio" class="radiosecelction" name="rdoY_@action.ID" id="rdo_@action.ID" value="" ids="@action.ID" /> <label for="rdoY_@action.ID">禁止</label><input type="radio" class="radiosecelction" name="rdoY_@action.ID" id="rdoY_@action.ID" value="" ids="@action.ID" />
<input type="button" value="清除" class="clearbtn" ids="@action.ID" />
}
}
</td>
</tr>
}
}
</table>
</div>
</body>
</html>
<script type="text/javascript">
$(".radiosecelction").click(function () {
var obj=$(this);
$.post(
"/UserInfo/SetUserAction",
{ "userId": '@user.ID', "actionId": obj.attr("ids"), "isPass": obj.val() },
function (data)
{
if (data == "OK") {
$.messager.show({
title: '提示',
msg: '权限修改成功',
showType: 'show'
});
}
else {
$.messager.show({
title: '提示',
msg: '权限修改失败',
showType: 'show'
});
} } )
});
$(".clearbtn").click(function () { var obj = $(this);
$.post(
"/UserInfo/ClearUserAction",
{ "userId": '@user.ID', "actionId": obj.attr("ids") },
function (data) {
if (data == "OK") {
obj.parent().find(".radiosecelction").removeAttr("checked")
$.messager.show({
title: '提示',
msg: '权限删除成功',
showType: 'show'
});
}
else {
$.messager.show({
title: '提示',
msg: '权限修改失败',
showType: 'show'
});
} } )
});
</script>

后天代码

  public ActionResult SetActionInfo()
{
int id = Request["id"] == null ? - : int.Parse(Request["id"]);
if (id >= )
{
//需要获取所有的权限信息进行展示
//需要获取用户已经拥有的权限信息进行展示
//需要获取用户的信息,如用户的名称
UserInfo user = userInfoService.LoadEntity(u => u.ID == id).FirstOrDefault();
ViewBag.User = user;
IList<ActionInfo> actionInfoList = actionInfoService.LoadEntity(a => a.DelFlag == (short)DelFlagEnum.Noraml).ToList();
ViewBag.ActionInfoList = actionInfoList;
IList<R_UserInfo_ActionInfo> userActionList = user.R_UserInfo_ActionInfo.ToList();
ViewBag.UserActionList = userActionList;
}
return View("SetUserActionInfo");
} //为用户修改权限
public ActionResult SetUserAction()
{
int userId = int.Parse(Request["userId"]);
int actionId = int.Parse(Request["actionId"]);
bool isPass = Request["isPass"] == "" ? true : false;
string result = userInfoService.SetUserAction(userId, actionId, isPass);
return Content(result);
}

OA之为用户设置角色和为用户设置权限的更多相关文章

  1. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(23)-设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用

    ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架搭建    (2):数据库访问层的设计Demo    (3):面向接口编程   (4 ):业务逻辑层的封装    ...

  2. 设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用

    设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架搭建    (2):数据库访问层的设计Demo ...

  3. Wordpress 为用户或角色 role 添加 capabilities(权限)

    首先查看角色具有哪些权限: $admin_role_set = get_role( 'administrator' )->capabilities; $author_role_set = get ...

  4. ASP.NET MVC+EF框架+EasyUI实现权限管理系列(22)-为用户设置角色

    ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架搭建    (2):数据库访问层的设计Demo    (3):面向接口编程   (4 ):业务逻辑层的封装    ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(27)-权限管理系统-分配用户给角色

    系列目录 分配用户给角色,跟分配角色给用户操作是基本一致的. 打开模块维护,展开SysRole模块添加一个操作码,并赋予权限 设置好之后将权限授权给管理员,在SysRole的index添加操作码与js ...

  6. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(27)-权限管理系统-分配用户给角色

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(27)-权限管理系统-分配用户给角色 分配用户给角色,跟分配角色给用户操作是基本一致的. 打开模块维护,展 ...

  7. Oracle操作管理之用户和角色

    1.用户管理 (1)建立用户(数据库验证) CREATE USER smith IDENTIFIED BY smith_pwd DEFAULTTABLESPACE users TEMPORARY TA ...

  8. MongoDB 的用户和角色权限

    副本和分片集群的安全设置参考这个:高级:https://files.cnblogs.com/files/sanduzxcvbnm/mongodb_advance.pdf 默认情况下,MongoDB实例 ...

  9. 为用户分配角色 C#

    开发网站时,在后台管理系统中,如果有多类角色,将会涉及到为角色分配用户的功能,或者是为用户选择角色.为用户分配角色相对来说操作的数据量比较小,因为系统所设定的角色不会有很多种.而如果是为角色分配用户, ...

随机推荐

  1. e621. Activating a Keystroke When Any Child Component Has Focus

    Normally, a keystroke registered on a component is activated when the component has the focus. This ...

  2. (转)关于三星cortex A9 Sate4412 开发板 uboot 启动的一些问题释疑

    说明:本文转载自:http://blog.csdn.net/gooogleman/article/details/17238079  作者:gooogleman                   日 ...

  3. linux -- 管道“|”

    利用Linux所提供的管道符“|”将两个命令隔开,管道符左边命令的输出就会作为管道符右边命令的输入.连续使用管道意味着第一个命令的输出会作为 第二个命令的输入,第二个命令的输出又会作为第三个命令的输入 ...

  4. ThinkPHP中调用PHPExcel

    //引入PHPExcel vendor('PHPExcel.PHPExcel'); // Create new PHPExcel object $objPHPExcel = new PHPExcel( ...

  5. php如何解决多线程同时读写一个文件的问题

    <?php header("content-type:text/html;charset=utf-8"); $fp = fopen("lock.txt", ...

  6. shiro+spring相关配置

    首先pom中添加所需jar包: <!-- shiro start --> <dependency> <groupId>org.apache.shiro</gr ...

  7. ROS节点理解--5

    理解 ROS节点(原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/) Description: 本教程主要介绍 ROS 图(graph)概念 并讨 ...

  8. haffman哈夫曼编码的实现

    <span style="font-size:18px;">/* 1.在一棵二叉树中,我们定义从A节点到B节点所经过的分支序列为从A节点到B节点的路径: 定义从A节点到 ...

  9. NodeJS-002-Expres启动

    1.打开app.js文件 2.在module.exports = app;之前输入: app.listen(8100,function(){ console.log("Server Star ...

  10. python2.0_s12_day21_web聊天室一

    本节内容: 项目实战:开发一个WEB聊天室 功能需求: 用户可以与好友一对一聊天 可以搜索.添加某人为好友 用户可以搜索和添加群 每个群有管理员可以审批用户的加群请求,群管理员可以用多个,群管理员可以 ...