ASP.NET.4.5.1+MVC5.0设置系统角色与权限(二)
程序员文章站
2024-02-14 23:55:40
系统角色篇
数据结构
用户管理
controller代码
复制代码 代码如下:
public class systemusercontroller : c...
系统角色篇
数据结构
用户管理
controller代码
复制代码 代码如下:
public class systemusercontroller : controller
{
//public void log()
//{
// string meg = "";
// int user = int.parse(cookiehelper.getvalue("sysuserid"));
// string ip = iphelper.getuserip;
// foreach (var item in routedata.values)
// {
// meg += item.key.toupper() + ":" + item.value + "|";
// }
// auditlogconfig.insertauditlog(meg, user, ip);
//}
systemuserrepository sysuserrepository = new systemuserrepository();
rolerepository roleryrepository = new rolerepository();
departmentrepository departmentryrepository = new departmentrepository();
jobrepository jobryrepository = new jobrepository();
#region 列表页
/// <summary>
/// 列表页
/// </summary>
/// <param name="page">当前页</param>
/// <returns></returns>
[authorize]
public actionresult index(int? page)
{
viewbag.controllername=routedata.values["controller"].tostring().tolower();
cookiehelper.del("logname");
var source = sysuserrepository.getpagemodellist(10, page ?? 1, -1);
return view(source);
}
#endregion
#region 添加管理员
/// <summary>
/// 添加页
/// </summary>
/// <param name="model">管理员实体类</param>
/// <returns></returns>
[authorize]
public actionresult add(systemuser model)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var rolelist = roleryrepository.getmodellistbystate(1);
viewbag.roleid = selectlistextension.toselectlist(rolelist, d => d.rolename, d => d.roleid.tostring());
var departmentlist = departmentryrepository.getmodellistbystate(1);
viewbag.departmentid = selectlistextension.toselectlist(departmentlist, d => d.departmentname, d => d.departmentid.tostring());
var joblist = jobryrepository.getmodellistbystate(1);
viewbag.jobid = selectlistextension.toselectlist(joblist, d => d.jobname, d => d.jobid.tostring());
// viewdata["state"] = selectlisthelper.getisornoselectlist(0);
return view();
}
/// <summary>
/// 添加事件
/// </summary>
/// <param name="model">实体类</param>
/// <param name="fc"></param>
/// <returns></returns>
[authorize, httppost, validateinput(false)]
public actionresult add(systemuser model, formcollection fc)
{
model.state = 1;
model.createtime = datetime.now;
sysuserrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="id">删除编号</param>
/// <returns></returns>
[authorize]
public actionresult delete(int id)
{
try
{
var model = sysuserrepository.getmodel(id);
if (model != null)
{
sysuserrepository.deletemodel(id);
return redirecttoaction("index");
}
else
return view("404");
//throw new exception("方法出错!");
}
catch (exception ex)
{
log4nethelper.invokeerrorlog(methodbase.getcurrentmethod().declaringtype, "删除方法出错-author:ryanding ip地址[" + iphelper.getuserip + "]" + "操作人id:" + cookiehelper.getvalue("systemuserid"), ex);
return view("404");
}
}
#endregion
#region 查询
[authorize]
public actionresult search(int? page)
{
string logname = "";
if (page == null)
{
logname = request.form["keyword"];
cookiehelper.setobj("keyword", 0, logname);
}
else
logname = cookiehelper.getvalue("keyword");
var query = querybuilder.create<systemuser>().like(d => d.logname, logname);
var source = sysuserrepository.getmodellist().where(query.expression);
return view(new pager<systemuser>(source, page ?? 1));
}
#endregion
#region 编辑
[authorize]
public actionresult edit(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = sysuserrepository.getmodel(id);
if (model != null)
{
var rolelist = roleryrepository.getmodellistbystate(1);
viewbag.roleid = selectlistextension.toselectlist(rolelist, d => d.rolename, d => d.roleid.tostring(),model.roleid);
var departmentlist = departmentryrepository.getmodellistbystate(1);
viewbag.departmentid = selectlistextension.toselectlist(departmentlist, d => d.departmentname, d => d.departmentid.tostring(), model.departmentid);
var joblist = jobryrepository.getmodellistbystate(1);
viewbag.jobid = selectlistextension.toselectlist(joblist, d => d.jobname, d => d.jobid.tostring(), model.jobid);
viewdata["state"] = selectlisthelper.getstateselectlist(model.state);
return view(model);
}
else
return view("404");
}
[authorize, acceptverbs(httpverbs.post), validateinput(false)]
public actionresult edit(int id, formcollection fc)
{
var model = sysuserrepository.getmodel(id);
if (model != null)
{
string password = model.password;
if (request.form["password"] != "")
{
updatemodel(model);
sysuserrepository.saveoreditmodel(model);
}
else
{
updatemodel(model);
model.password = password;
sysuserrepository.saveoreditmodel(model);
}
return redirecttoaction("index");
}
else
return view("404");
}
#endregion
#region 用户名是否可用
//检测用户名是否可用
[httppost]
public actionresult getusers(string param, string name)
{
if (sysuserrepository.isexist(param))
return content("y");
else
return content("用户名已存在");
}
#endregion
public bool login()
{
try
{
//todo:
throw new exception("方法出错!");
}
catch (exception ex)
{
log4nethelper.invokeerrorlog(methodbase.getcurrentmethod().declaringtype, "登录方法login出错-author:ryanding ip地址[" + iphelper.getuserip + "]" + "操作人id:" + cookiehelper.getvalue("systemuserid"), ex);
return false;
}
return true;
}
}
view代码
index.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.systemuser>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/systemuser/add">添加用户</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">用户编号</td>
<td class="rgtd3">登录名</td>
<td class="rgtd3">手机</td>
<td class="rgtd3">email</td>
<td class="rgtd3">昵称</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.systemuserid</td>
<td class="rgtd3">@(item.logname)</td>
<td class="rgtd3">@item.mobile</td>
<td class="rgtd3">@item.email</td>
<td class="rgtd3">@item.truename</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/systemuser/delete/@item.systemuserid">删除</a> | <a href="/systemuser/edit/@item.systemuserid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
<div class="rg5">
@uihelper.pageshelper(viewbag.controllername, model.totalpages, model.pageindex, model.pagesize, model.totalcount, model.haspreviouspage, model.hasnextpage, model.pagelist)
</div>
</div>
</div>
<script>
//菜单显示
$("#@(viewbag.controllername)sys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".@(viewbag.controllername)sys").each(function (index, item) {
$(this).show();
});
</script>
add.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>添加用户</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">用户名:</dd>
<dd>
<input name="logname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd class="dc1">昵称:</dd>
<dd>
<input name="truename" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd class="dc1">email:</dd>
<dd>
<input type="text" name="email" id="email" class="rgtxt2" />
</dd>
</dl>
<dl>
<dd class="dc1">手机号:</dd>
<dd>
<input type="text" name="mobile" id="mobile" class="rgtxt2" />
</dd>
</dl>
<dl>
<dd class="dc1">密码:</dd>
<dd>
<input type="text" name="password" id="password" class="rgtxt2" />
</dd>
</dl>
<dl>
<dd class="dc1">确认密码:</dd>
<dd>
<input type="text" name="passwordto" id="passwordto" class="rgtxt2" />
</dd>
</dl>
<dl>
<dd class="dc1">岗位:</dd>
<dd>
@html.dropdownlist("jobid", viewbag.jobid as selectlist)
</dd>
</dl>
<dl>
<dd class="dc1">部门:</dd>
<dd>
@html.dropdownlist("departmentid", viewbag.departmentid as selectlist)
</dd>
</dl>
<dl>
<dd class="dc1">角色:</dd>
<dd>
@html.dropdownlist("roleid", viewbag.roleid as selectlist)
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#@(viewbag.controllername)sys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".@(viewbag.controllername)sys").each(function (index, item) {
$(this).show();
});
</script>
edit.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.models.systemuser
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>编辑用户</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">用户名:</dd>
<dd>
<input name="logname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@model.logname"/>
</dd>
</dl>
<dl>
<dd class="dc1">昵称:</dd>
<dd>
<input name="truename" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@model.truename" />
</dd>
</dl>
<dl>
<dd class="dc1">email:</dd>
<dd>
<input type="text" name="email" id="email" class="rgtxt2" value="@model.email" />
</dd>
</dl>
<dl>
<dd class="dc1">手机号:</dd>
<dd>
<input type="text" name="mobile" id="mobile" class="rgtxt2" value="@model.mobile" />
</dd>
</dl>
<dl>
<dd class="dc1">修改密码:</dd>
<dd>
<input type="text" name="password" id="password" class="rgtxt2" value="@model.password" />
</dd>
</dl>
<dl>
<dd class="dc1">岗位:</dd>
<dd>
@html.dropdownlist("jobid", viewbag.jobid as selectlist)
</dd>
</dl>
<dl>
<dd class="dc1">部门:</dd>
<dd>
@html.dropdownlist("departmentid", viewbag.departmentid as selectlist)
</dd>
</dl>
<dl>
<dd class="dc1">角色:</dd>
<dd>
@html.dropdownlist("roleid", viewbag.roleid as selectlist)
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#@(viewbag.controllername)sys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".@(viewbag.controllername)sys").each(function (index, item) {
$(this).show();
});
</script>
search.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.systemuser>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/systemuser/add">添加用户</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">用户编号</td>
<td class="rgtd3">登录名</td>
<td class="rgtd3">手机</td>
<td class="rgtd3">email</td>
<td class="rgtd3">昵称</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.systemuserid</td>
<td class="rgtd3">@(item.logname)</td>
<td class="rgtd3">@item.mobile</td>
<td class="rgtd3">@item.email</td>
<td class="rgtd3">@item.truename</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/systemuser/delete/@item.systemuserid">删除</a> | <a href="/systemuser/edit/@item.systemuserid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
</div>
</div>
<script>
//菜单显示
$("#@(viewbag.controllername)sys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".@(viewbag.controllername)sys").each(function (index, item) {
$(this).show();
});
</script>
角色管理
controller代码
复制代码 代码如下:
public class rolecontroller : controller
{
rolerepository roleryrepository = new rolerepository();
menurepository menurepository = new menurepository();
rolemenumappingrepository rmmrepositoy = new rolemenumappingrepository();
#region 列表
/// <summary>
/// 默认页面
/// </summary>
/// <returns></returns>
///
[authorize]
public actionresult index(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var source = roleryrepository.getmodellist();
return view(roleryrepository.getpagemodellist(source, 10, page ?? 1));
}
#endregion
#region 添加
/// <summary>
/// 添加页
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
[authorize]
public actionresult add(role model)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var menu = menurepository.getmodellistbystate(1);
viewbag.menu = new selectlist(menu, "menuid", "menuname");
// viewdata["state"] = selectlisthelper.getisornoselectlist(0);
return view();
}
public string log()
{
string meg = "";
//int user = int.parse(cookiehelper.getvalue("sysuserid"));
//string ip = iphelper.getuserip;
foreach (var item in routedata.values)
{
meg += item.key.toupper() + ":" + item.value + "|";
}
return meg;
}
/// <summary>
/// 添加事件
/// </summary>
/// <param name="model">实体类</param>
/// <param name="fc"></param>
/// <returns></returns>
[authorize, httppost, validateinput(false)]
public actionresult add(role model, formcollection fc, int[] menu)
{
try
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
model.state = 1;
model.createtime = datetime.now;
roleryrepository.saveoreditmodel(model);
if (menu.length > 0)
{
foreach (int gsi in menu)
{
rolemenumapping rmm = new rolemenumapping();
rmm.menuid = gsi;
rmm.roleid = model.roleid;
rmmrepositoy.saveoreditmodel(rmm);
}
}
else
{
return redirecttoaction("index");
}
}
catch (exception ex)
{
log4nethelper.invokeerrorlog(methodbase.getcurrentmethod().declaringtype, viewbag.controllername + "添加方法出错-author:ryanding ip地址[" + iphelper.getuserip + "]" + "操作人id:" + cookiehelper.getvalue("systemuserid") + "当前来源信息:" + log(), ex);
}
return view("404");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="id">删除编号</param>
/// <returns></returns>
[authorize]
public actionresult delete(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = roleryrepository.getmodel(id);
model.state = 0;
if (model != null)
{
roleryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
}
#endregion
#region 查询
[authorize]
public actionresult search(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
string name = "";
if (page == null)
{
name = request.form["keyword"];
cookiehelper.setobj("keyword", 0, name);
}
else
name = cookiehelper.getvalue("keyword");
var query = querybuilder.create<role>().like(d => d.rolename, name);
var source = roleryrepository.getmodellist().where(query.expression);
return view(new pager<role>(source, page ?? 1, 10));
}
#endregion
#region 编辑
[authorize]
public actionresult edit(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var rmmlist = rmmrepositoy.getmodellist().where(d => d.roleid == id);
var menu = menurepository.getmodellistbystate(1);
viewbag.menu = new selectlist(menu, "menuid", "menuname", string.join(",", rmmlist.select(p => p.menuid)));
var model = roleryrepository.getmodel(id);
if (model != null)
{
viewdata["state"] = selectlisthelper.getstateselectlist(model.state);
return view(model);
}
else
return view("404");
}
[authorize, acceptverbs(httpverbs.post), validateinput(false)]
public actionresult edit(int id, formcollection fc, int[] menu)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = roleryrepository.getmodel(id);
if (model != null)
{
if (menu.length > 0)
{
rmmrepositoy.deletemodel(rmmrepositoy.getmodellist().where(d => d.roleid == model.roleid));
foreach (int gsi in menu)
{
rolemenumapping rmm = new rolemenumapping();
rmm.menuid = gsi;
rmm.roleid = model.roleid;
rmmrepositoy.saveoreditmodel(rmm);
}
}
updatemodel(model);
roleryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
}
#endregion
}
view代码
index.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.role>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd2">角色名称</td>
<td class="rgtd3">角色内容</td>
<td class="rgtd3">创建时间</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.roleid</td>
<td class="rgtd2">@item.rolename</td>
<td class="rgtd3">@item.rolecontent</td>
<td class="rgtd3">@string.format("{0:yyyy-mm-dd}", item.createtime)</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/@viewbag.controllername/delete/@item.roleid">删除</a> | <a href="/@viewbag.controllername/edit/@item.roleid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
<div class="rg5">
@uihelper.pageshelper(viewbag.controllername, model.totalpages, model.pageindex, model.pagesize, model.totalcount, model.haspreviouspage, model.hasnextpage, model.pagelist);
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
add.cshtml
复制代码 代码如下:
@using sjcrm.helpers
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>添加</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">角色名称:</dd>
<dd>
<input name="rolename" type="text" class="rgtxt2" datatype="*" nullmsg="请输入名称" />
</dd>
</dl>
<dl>
<dd class="dc1">角色权限:</dd>
<dd>
@html.checkboxlist("menu")
</dd>
</dl>
<dl>
<dd class="dc1">角色内容:</dd>
<dd>
<textarea rows="10" cols="82" name="rolecontent" id="rolecontent"></textarea>
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
edit.cshtml
复制代码 代码如下:
@using sjcrm.helpers
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.models.role
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>编辑</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">角色名称:</dd>
<dd>
<input name="rolename" type="text" class="rgtxt2" datatype="*" nullmsg="请输入名称" value="@model.rolename"/>
</dd>
</dl>
<dl>
<dd class="dc1">角色权限:</dd>
<dd>
@html.checkboxlist("menu")
</dd>
</dl>
<dl>
<dd class="dc1">角色内容:</dd>
<dd>
<textarea rows="10" cols="82" name="rolecontent" id="rolecontent">@model.rolename</textarea>
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
search.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.role>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd2">角色名称</td>
<td class="rgtd3">角色内容</td>
<td class="rgtd3">创建时间</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.roleid</td>
<td class="rgtd2">@item.rolename</td>
<td class="rgtd3">@item.rolecontent</td>
<td class="rgtd3">@string.format("{0:yyyy-mm-dd}", item.createtime)</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/@viewbag.controllername/delete/@item.roleid">删除</a> | <a href="/@viewbag.controllername/edit/@item.roleid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
菜单管理
controller代码
复制代码 代码如下:
public class menucontroller : controller
{
menurepository repository = new menurepository();
#region 列表
/// <summary>
/// 默认页面
/// </summary>
/// <returns></returns>
///
[authorize]
public actionresult index(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var source = repository.getmodellistbystate(1);
return view(repository.getpagemodellist(source, 10, page ?? 1));
}
#endregion
#region 添加
/// <summary>
/// 添加页
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
[authorize]
public actionresult add(menu model)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
// viewdata["state"] = selectlisthelper.getisornoselectlist(0);
return view();
}
/// <summary>
/// 添加事件
/// </summary>
/// <param name="model">实体类</param>
/// <param name="fc"></param>
/// <returns></returns>
[authorize, httppost, validateinput(false)]
public actionresult add(menu model, formcollection fc)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
model.state = 1;
model.createtime = datetime.now;
repository.saveoreditmodel(model);
return redirecttoaction("index");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="id">删除编号</param>
/// <returns></returns>
[authorize]
public actionresult delete(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = repository.getmodel(id);
model.state = 0;
if (model != null)
{
repository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
//var model = categoryrepository.getmodel(id);
//if (model != null)
//{
// categoryrepository.deletemodel(id);
// return redirecttoaction("index");
//}
//else
// return view("404");
}
#endregion
#region 查询
[authorize]
public actionresult search(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
string name = "";
if (page == null)
{
name = request.form["keyword"];
cookiehelper.setobj("keyword", 0, name);
}
else
name = cookiehelper.getvalue("keyword");
var query = querybuilder.create<menu>().like(d => d.menuname, name);
var source = repository.getmodellist().where(query.expression);
return view(new pager<menu>(source, page ?? 1, 10));
}
#endregion
#region 编辑
[authorize]
public actionresult edit(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = repository.getmodel(id);
if (model != null)
{
viewdata["state"] = selectlisthelper.getstateselectlist(model.state);
return view(model);
}
else
return view("404");
}
[authorize, acceptverbs(httpverbs.post), validateinput(false)]
public actionresult edit(int id, formcollection fc)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = repository.getmodel(id);
if (model != null)
{
updatemodel(model);
repository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
}
#endregion
}
view代码
index.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.menu>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd3">菜单名称</td>
<td class="rgtd3">别名样式</td>
<td class="rgtd3">连接地址</td>
<td class="rgtd3">创建时间</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.menuid</td>
<td class="rgtd3">@item.menuname</td>
<td class="rgtd3">@item.alias</td>
<td class="rgtd3">@item.url</td>
<td class="rgtd3">@string.format("{0:yyyy-mm-dd}", item.createtime)</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/@viewbag.controllername/delete/@item.menuid">删除</a> | <a href="/@viewbag.controllername/edit/@item.menuid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
<div class="rg5">
@uihelper.pageshelper(viewbag.controllername, model.totalpages, model.pageindex, model.pagesize, model.totalcount, model.haspreviouspage, model.hasnextpage, model.pagelist);
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
add.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>添加菜单</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">菜单名称:</dd>
<dd>
<input name="menuname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd class="dc1">连接地址:</dd>
<dd>
<input name="url" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd class="dc1">别名样式:</dd>
<dd>
<input name="alias" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
edit.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.models.menu
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>编辑</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">菜单名称:</dd>
<dd>
<input name="menuname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@model.menuname" />
</dd>
</dl>
<dl>
<dd class="dc1">连接地址:</dd>
<dd>
<input name="url" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@model.url" />
</dd>
</dl>
<dl>
<dd class="dc1">别名样式:</dd>
<dd>
<input name="alias" type="text" class="rgtxt2" datatype="n" nullmsg="请输入产品名称" value="@model.alias" />
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
search.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.menu>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd3">菜单名称</td>
<td class="rgtd3">别名样式</td>
<td class="rgtd3">连接地址</td>
<td class="rgtd3">创建时间</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.menuid</td>
<td class="rgtd3">@item.menuname</td>
<td class="rgtd3">@item.alias</td>
<td class="rgtd3">@item.url</td>
<td class="rgtd3">@string.format("{0:yyyy-mm-dd}", item.createtime)</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/@viewbag.controllername/delete/@item.menuid">删除</a> | <a href="/@viewbag.controllername/edit/@item.menuid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
部门管理
controller代码
复制代码 代码如下:
public class departmentcontroller : controller
{
departmentrepository departmentryrepository = new departmentrepository();
#region 列表
/// <summary>
/// 默认页面
/// </summary>
/// <returns></returns>
///
[authorize]
public actionresult index(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var source = departmentryrepository.getmodellist();
return view(departmentryrepository.getpagemodellist(source, 10, page ?? 1));
}
#endregion
#region 添加
/// <summary>
/// 添加页
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
[authorize]
public actionresult add(department model)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
// viewdata["state"] = selectlisthelper.getisornoselectlist(0);
return view();
}
/// <summary>
/// 添加事件
/// </summary>
/// <param name="model">实体类</param>
/// <param name="fc"></param>
/// <returns></returns>
[authorize, httppost, validateinput(false)]
public actionresult add(department model, formcollection fc)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
model.state = 1;
model.createtime = datetime.now;
departmentryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="id">删除编号</param>
/// <returns></returns>
[authorize]
public actionresult delete(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = departmentryrepository.getmodel(id);
model.state = 0;
if (model != null)
{
departmentryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
//var model = categoryrepository.getmodel(id);
//if (model != null)
//{
// categoryrepository.deletemodel(id);
// return redirecttoaction("index");
//}
//else
// return view("404");
}
#endregion
#region 查询
[authorize]
public actionresult search(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
string jobname = "";
if (page == null)
{
jobname = request.form["keyword"];
cookiehelper.setobj("keyword", 0, jobname);
}
else
jobname = cookiehelper.getvalue("keyword");
var query = querybuilder.create<department>().like(d => d.departmentname, jobname);
var source = departmentryrepository.getmodellist().where(query.expression);
return view(new pager<department>(source, page ?? 1, 10));
}
#endregion
#region 编辑
[authorize]
public actionresult edit(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = departmentryrepository.getmodel(id);
if (model != null)
{
viewdata["state"] = selectlisthelper.getstateselectlist(model.state);
return view(model);
}
else
return view("404");
}
[authorize, acceptverbs(httpverbs.post), validateinput(false)]
public actionresult edit(int id, formcollection fc)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = departmentryrepository.getmodel(id);
if (model != null)
{
updatemodel(model);
departmentryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
}
#endregion
}
view代码
index.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.department>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd2">部门名称</td>
<td class="rgtd3">是否销售</td>
<td class="rgtd3">创建时间</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.departmentid</td>
<td class="rgtd2">@item.departmentname</td>
<td class="rgtd3">@(item.issale == 1 ? "是" : "否")</td>
<td class="rgtd3">@string.format("{0:yyyy-mm-dd}", item.createtime)</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/@viewbag.controllername/delete/@item.departmentid">删除</a> | <a href="/@viewbag.controllername/edit/@item.departmentid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
<div class="rg5">
@uihelper.pageshelper(viewbag.controllername, model.totalpages, model.pageindex, model.pagesize, model.totalcount, model.haspreviouspage, model.hasnextpage, model.pagelist);
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
add.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>添加</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">部门名称:</dd>
<dd>
<input name="departmentname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd class="dc1">是否销售:</dd>
<dd>
<select name="issale">
<option value="1">是</option>
<option value="0">否</option>
</select>
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
edit.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.models.department
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>编辑</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">部门名称:</dd>
<dd>
<input name="departmentname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@model.departmentname" />
</dd>
</dl>
<dl>
<dd class="dc1">是否销售:</dd>
<dd>
@uihelper.isselect("issale", @model.issale.tostring());
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
search.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.department>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd2">部门名称</td>
<td class="rgtd3">是否销售</td>
<td class="rgtd3">创建时间</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.departmentid</td>
<td class="rgtd2">@item.departmentname</td>
<td class="rgtd3">@(item.issale == 1 ? "是" : "否")</td>
<td class="rgtd3">@string.format("{0:yyyy-mm-dd}", item.createtime)</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/@viewbag.controllername/delete/@item.departmentid">删除</a> | <a href="/@viewbag.controllername/edit/@item.departmentid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
岗位管理
controller代码
复制代码 代码如下:
public class jobcontroller : controller
{
jobrepository jobryrepository = new jobrepository();
#region 岗位列表
/// <summary>
/// 默认页面
/// </summary>
/// <returns></returns>
///
[authorize]
public actionresult index(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var source = jobryrepository.getmodellistbystate(1);
return view(jobryrepository.getpagemodellist(source, 10, page ?? 1));
}
#endregion
#region 添加
/// <summary>
/// 添加页
/// </summary>
/// <param name="model">实体类</param>
/// <returns></returns>
[authorize]
public actionresult add(job model)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
// viewdata["state"] = selectlisthelper.getisornoselectlist(0);
return view();
}
/// <summary>
/// 添加事件
/// </summary>
/// <param name="model">实体类</param>
/// <param name="fc"></param>
/// <returns></returns>
[authorize, httppost, validateinput(false)]
public actionresult add(job model, formcollection fc)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
model.state = 1;
model.createtime = datetime.now;
jobryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="id">删除编号</param>
/// <returns></returns>
[authorize]
public actionresult delete(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = jobryrepository.getmodel(id);
model.state = 0;
if (model != null)
{
jobryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
//var model = categoryrepository.getmodel(id);
//if (model != null)
//{
// categoryrepository.deletemodel(id);
// return redirecttoaction("index");
//}
//else
// return view("404");
}
#endregion
#region 查询
[authorize]
public actionresult search(int? page)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
string jobname = "";
if (page == null)
{
jobname = request.form["keyword"];
cookiehelper.setobj("keyword", 0, jobname);
}
else
jobname = cookiehelper.getvalue("keyword");
var query = querybuilder.create<job>().like(d => d.jobname, jobname);
var source = jobryrepository.getmodellist().where(query.expression);
return view(new pager<job>(source, page ?? 1, 10));
}
#endregion
#region 编辑
[authorize]
public actionresult edit(int id)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = jobryrepository.getmodel(id);
if (model != null)
{
viewdata["state"] = selectlisthelper.getstateselectlist(model.state);
return view(model);
}
else
return view("404");
}
[authorize, acceptverbs(httpverbs.post), validateinput(false)]
public actionresult edit(int id, formcollection fc)
{
viewbag.controllername = routedata.values["controller"].tostring().tolower();
var model = jobryrepository.getmodel(id);
if (model != null)
{
updatemodel(model);
jobryrepository.saveoreditmodel(model);
return redirecttoaction("index");
}
else
return view("404");
}
#endregion
}
view代码
index.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.job>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd2">岗位名称</td>
<td class="rgtd3">岗位说明</td>
<td class="rgtd3">是否主管</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.jobid</td>
<td class="rgtd2">@item.jobname</td>
<td class="rgtd3">@item.jobcontent</td>
<td class="rgtd3">@(item.ismanager == 1 ? "是" : "否")</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/job/delete/@item.jobid">删除</a> | <a href="/job/edit/@item.jobid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
<div class="rg5">
@uihelper.pageshelper(viewbag.controllername, model.totalpages, model.pageindex, model.pagesize, model.totalcount, model.haspreviouspage, model.hasnextpage, model.pagelist);
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
add.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>添加</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">岗位名称:</dd>
<dd>
<input name="jobname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" />
</dd>
</dl>
<dl>
<dd class="dc1">是否主管:</dd>
<dd>
<select name="ismanager">
<option value="1">是</option>
<option value="0">否</option>
</select>
</dd>
</dl>
<dl>
<dd class="dc1">岗位说明:</dd>
<dd>
<textarea rows="10" cols="82" name="jobcontent" id="jobcontent"></textarea>
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
edit.cshtml
复制代码 代码如下:
@{
viewbag.title = "add";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.models.job
<div class="contrgcon">
<div class="rgtit3">
<div class="tit1">
<h3>编辑</h3>
</div>
<div class="rgtit3con">
@using (html.beginform())
{
<dl>
<dd class="dc1">岗位名称:</dd>
<dd>
<input name="jobname" type="text" class="rgtxt2" datatype="*" nullmsg="请输入产品名称" value="@model.jobname" />
</dd>
</dl>
<dl>
<dd class="dc1">是否主管:</dd>
<dd>
@uihelper.isselect("ismanager",model.ismanager.tostring());
</dd>
</dl>
<dl>
<dd class="dc1">岗位说明:</dd>
<dd>
<textarea rows="10" cols="82" name="jobcontent" id="jobcontent">@model.jobcontent</textarea>
</dd>
</dl>
<dl>
<dd>
<input type="submit" value="提 交" class="rgbut4" />
</dd>
</dl>
}
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
@*<script src="/content/scripts/validform_v5.3.2.js"></script>
<script>
$(document).ready(function () {
$("#addform").validform({
tiptype: 3
});
});
</script>*@
<script src="@url.content("~/content/kindeditor/kindeditor-min.js")" type="text/javascript"></script>
@*<script type="text/javascript">
kindeditor.ready(function (k) {
k.create('#jobcontent', {
allowfilemanager: true
});
});
</script>*@
search.cshtml
复制代码 代码如下:
@{
viewbag.title = "index";
layout = "~/views/shared/_layout.cshtml";
}
@model sjcrm.helpers.pager<sjcrm.models.job>
<div class="contrgcon">
<div class="contrg_list">
<div class="rgtit">
<form method="post" action="/@viewbag.controllername/search">
<dl>
<dd>关键词:</dd>
<dd>
<input name="keyword" type="text" class="rgtxt2" /></dd>
<dd>
<input type="submit" value="查 询" class="rgbut1" /></dd>
</dl>
</form>
</div>
<div class="rgc">
<dl class="rgt11">
<dt>
<span class="sple"><a href="/@viewbag.controllername/add">添加</a></span>
</dt>
</dl>
<div class="rg3">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="rgtd2">编号</td>
<td class="rgtd2">岗位名称</td>
<td class="rgtd3">岗位说明</td>
<td class="rgtd3">是否主管</td>
<td class="rgtd3">状态</td>
<td class="rgtd4">操作</td>
</tr>
</table>
</div>
<div class="rg4">
@{int classnum = 1;}
@foreach (var item in model)
{
<table width="100%" border="0" cellspacing="0" cellpadding="0" @if (classnum % 2 == 0)
{<text>class="rgbg2"</text>}>
<tr>
<td class="rgtd2">@item.jobid</td>
<td class="rgtd2">@item.jobname</td>
<td class="rgtd3">@item.jobcontent</td>
<td class="rgtd3">@(item.ismanager == 1 ? "是" : "否")</td>
<td class="rgtd3">@(item.state == 1 ? "有效" : "无效")</td>
<td class="rgtd4"><a href="/job/delete/@item.jobid">删除</a> | <a href="/job/edit/@item.jobid">编辑</a> </td>
</tr>
</table>
classnum = classnum + 1;
}
</div>
</div>
</div>
</div>
<script>
//菜单显示
$("#systemusersys").addclass("hbg");
$("#@(viewbag.controllername)").removeclass("navli");
$("#@(viewbag.controllername)").addclass("navlihg");
$(".systemusersys").each(function (index, item) {
$(this).show();
});
</script>
上一篇: c#泛型学习详解 创建线性链表
下一篇: 算法-合并两个排序的链表