OA之为用户设置角色和为用户设置权限
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之为用户设置角色和为用户设置权限的更多相关文章
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(23)-设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2):数据库访问层的设计Demo (3):面向接口编程 (4 ):业务逻辑层的封装 ...
- 设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用
设置角色遗留问题和为权限设置角色以及EasyUI Tabs的使用 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2):数据库访问层的设计Demo ...
- Wordpress 为用户或角色 role 添加 capabilities(权限)
首先查看角色具有哪些权限: $admin_role_set = get_role( 'administrator' )->capabilities; $author_role_set = get ...
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(22)-为用户设置角色
ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1):框架搭建 (2):数据库访问层的设计Demo (3):面向接口编程 (4 ):业务逻辑层的封装 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(27)-权限管理系统-分配用户给角色
系列目录 分配用户给角色,跟分配角色给用户操作是基本一致的. 打开模块维护,展开SysRole模块添加一个操作码,并赋予权限 设置好之后将权限授权给管理员,在SysRole的index添加操作码与js ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(27)-权限管理系统-分配用户给角色
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(27)-权限管理系统-分配用户给角色 分配用户给角色,跟分配角色给用户操作是基本一致的. 打开模块维护,展 ...
- Oracle操作管理之用户和角色
1.用户管理 (1)建立用户(数据库验证) CREATE USER smith IDENTIFIED BY smith_pwd DEFAULTTABLESPACE users TEMPORARY TA ...
- MongoDB 的用户和角色权限
副本和分片集群的安全设置参考这个:高级:https://files.cnblogs.com/files/sanduzxcvbnm/mongodb_advance.pdf 默认情况下,MongoDB实例 ...
- 为用户分配角色 C#
开发网站时,在后台管理系统中,如果有多类角色,将会涉及到为角色分配用户的功能,或者是为用户选择角色.为用户分配角色相对来说操作的数据量比较小,因为系统所设定的角色不会有很多种.而如果是为角色分配用户, ...
随机推荐
- Docker之删除container和image
删除所有停止的container: docker rm $(docker ps -a -q) 删除所有未标记的image docker rmi $(docker images | grep " ...
- e671. 在缓冲图像中存取像素
// Get a pixel int rgb = bufferedImage.getRGB(x, y); // Get all the pixels int w = bufferedImage.get ...
- e650. 激活事件
An object wishing to fire item events must implement ItemSelectable. This example shows typical code ...
- Nodejs入门手记 (01):Hello World的WEB程序
声明:本文为原创文章,如需转载,请注明来源并保留原文链接Allong,谢谢! “滚滚长江东逝水,浪花淘尽英雄.是非成败转头空.” - <临江仙·杨慎·明> 很熟悉的旋律,鸡汤了一下:高考是 ...
- PNG透明兼容IE6的几种方法(转)
png 透明针对 IE6 一直是件挺麻烦的事情,使用的方法也是各有不同,大多的原理是用 IE 的滤镜来解决的. 语法: filter:progid:DXImageTransform.Microsoft ...
- Android 利用cursor来进行排序(转至http://blog.csdn.net/yangzongquan/article/details/6547860)
主要思路是:override move系列的方法,让cursor以自己想要的顺序来移动,从而达到对cursor排序的目的.比如数组A0里有 4(0),3(1),1(2),2(3),括号内为位置,排序后 ...
- opencv播放视屏并控制位置
原文地址:http://blog.csdn.net/augusdi/article/details/9000592 cvGetCaptureProperty是我们需要使用到的获取视频属性的函数. do ...
- delphi7中添加QuickRep
具体的方法是: delphi主菜单的Project|Options命令, 在Package选项卡的Desing packages列表中如果可以看到QuickReport Components选项, 那 ...
- mybatis由浅入深day02_9逆向工程
9 逆向工程 9.1 什么是逆向工程 mybaits需要程序员自己编写sql语句,mybatis官方提供逆向工程 可以针对单表自动生成mybatis执行所需要的代码(mapper.java,mappe ...
- mybatis由浅入深day01_4.7根据用户名称模糊查询用户信息_4.8添加用户((非)自增主键返回)
4.7 根据用户名称模糊查询用户信息 4.7.1 映射文件 使用User.xml,添加根据用户名称模糊查询用户信息的sql语句. 4.7.2 程序代码 控制台: 4.8 添加用户 4.8.1 映射文件 ...