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. e637. 向剪切板获取和粘贴文本

    This examples defines methods for getting and setting text on the system clipboard. // If a string i ...

  2. C#多播委托/多播代理

    定义:委托是一种在对象里保存方法引用的类型,同时也是一种类型安全的函数指针.理解委托的一种方式可以把委托的作用当作是给方法签名指定名称.委托的定义类似于方法的定义,但没有方法体,定义的委托名前要加上关 ...

  3. php header函数下载文件实现代码

    在php中header函数的使用很大,header不但可以向客户端发送原始的 HTTP 报头信息,同时还可以直接实现文件下载操作 header函数最常用的不是用于下载而是用于发送http类的 跳转 它 ...

  4. 10个开发中常用的PHP代码样例

    一.黑名单过滤 function is_spam($text, $file, $split = ':', $regex = false){ $handle = fopen($file, 'rb'); ...

  5. 访问GitLab的PostgreSQL数据库

    1.登陆gitlab的安装服务查看配置文件 cat /var/opt/gitlab/gitlab-rails/etc/database.yml production: adapter: postgre ...

  6. 启用lazyload插件,减少图片加载

    使用lazyload的js插件,减少图片加载,提高页面加载速度和节省流量.虽然这个头像是第三方服务器来的,不消费博客的流量,但是能节省部分访客的加载时间,也是不错的哦. 用lazyload插件,只是后 ...

  7. PVS 7.6 部署教程

    PVS 7.6 部署教程 1 PVS介绍 Citrix Provisioning Services採用流技术通过网络将单一标准桌面镜像,包含操作系统和软件按需交付给物理虚拟桌面.一方面实现同型号机器单 ...

  8. 异常处理----使用 try…catch…finally 处理异常

    使用 try…catch…finally 处理异常 异常处理是通过try-catch-finally语句实现的. try { ...... //可能产生异常的代码 } catch( Exception ...

  9. sublime常用插件及配置

      以下是我的sublime插件列表: Side​Bar​Enhancements增强版侧边栏 这个插件官方不支持通过package安装了,只能手动了,下载地址https://github.com/S ...

  10. swift - UITextView的用法

    1,多行文本控件的创建 textView.frame = CGRect(x:50,y:180,width:self.view.bounds.size.width - 100,height:50) te ...