using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using App.Common;
using App.Models;
using Microsoft.Practices.Unity;
using App.IBLL;
using App.Models.Sys;
namespace App.Admin.Controllers
{
public class SysRoleController : BaseController
{
//
// GET: /SysRole/
[Dependency]
public ISysRoleBLL m_BLL { get; set; }
ValidationErrors errors = new ValidationErrors();
[SupportFilter]
public ActionResult Index()
{
ViewBag.Perm = GetPermission();
return View();
}
[SupportFilter(ActionName="Index")]
public JsonResult GetList(GridPager pager,string queryStr)
{
List<SysRoleModel> list = m_BLL.GetList(ref pager, queryStr);
var json = new
{
total = pager.totalRows,
rows = (from r in list
select new SysRoleModel()
{
Id = r.Id,
Name = r.Name,
Description = r.Description,
CreateTime = r.CreateTime,
CreatePerson = r.CreatePerson,
UserName = r.UserName
}).ToArray()
};
return Json(json);
}
#region 创建
[SupportFilter]
public ActionResult Create()
{
ViewBag.Perm = GetPermission();
return View();
}
[HttpPost]
[SupportFilter]
public JsonResult Create(SysRoleModel model)
{
model.Id = ResultHelper.NewId;
model.CreateTime = ResultHelper.NowTime;
if (model != null && ModelState.IsValid)
{
if (m_BLL.Create(ref errors, model))
{
LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "SysRole");
return Json(JsonHandler.CreateMessage(1, Suggestion.InsertSucceed));
}
else
{
string ErrorCol = errors.Error;
LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "SysRole");
return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail + ErrorCol));
}
}
else
{
return Json(JsonHandler.CreateMessage(0, Suggestion.InsertFail));
}
}
#endregion
#region 修改
[SupportFilter]
public ActionResult Edit(string id)
{
ViewBag.Perm = GetPermission();
SysRoleModel entity = m_BLL.GetById(id);
return View(entity);
}
[HttpPost]
[SupportFilter]
public JsonResult Edit(SysRoleModel model)
{
if (model != null && ModelState.IsValid)
{
if (m_BLL.Edit(ref errors, model))
{
LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "SysRole");
return Json(JsonHandler.CreateMessage(1, Suggestion.EditSucceed));
}
else
{
string ErrorCol = errors.Error;
LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "SysRole");
return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail + ErrorCol));
}
}
else
{
return Json(JsonHandler.CreateMessage(0, Suggestion.EditFail));
}
}
#endregion
#region 详细
[SupportFilter]
public ActionResult Details(string id)
{
ViewBag.Perm = GetPermission();
SysRoleModel entity = m_BLL.GetById(id);
return View(entity);
}
#endregion
#region 删除
[HttpPost]
[SupportFilter]
public JsonResult Delete(string id)
{
if (!string.IsNullOrWhiteSpace(id))
{
if (m_BLL.Delete(ref errors, id))
{
LogHandler.WriteServiceLog(GetUserId(), "Id:" + id, "成功", "删除", "SysRole");
return Json(JsonHandler.CreateMessage(1, Suggestion.DeleteSucceed));
}
else
{
string ErrorCol = errors.Error;
LogHandler.WriteServiceLog(GetUserId(), "Id" + id + "," + ErrorCol, "失败", "删除", "SysRole");
return Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail + ErrorCol));
}
}
else
{
return Json(JsonHandler.CreateMessage(0, Suggestion.DeleteFail));
}
}
#endregion
}
}
@using App.Admin;
@using App.Common;
@using App.Models.Sys;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Index_Layout.cshtml";
List<permModel> perm = (List<permModel>)ViewBag.Perm;
if (perm == null)
{
perm = new List<permModel>();
}
}
<div class="mvctool">
<input id="txtQuery" type="text" class="searchText"/>
@Html.ToolButton("btnQuery", "icon-search", "查询", perm, "Query", true)
@Html.ToolButton("btnCreate", "icon-add", "新增", perm, "Create", true)
@Html.ToolButton("btnEdit", "icon-edit", "编辑", perm, "Edit", true)
@Html.ToolButton("btnDetails", "icon-details", "详细", perm, "Details", true)
@Html.ToolButton("btnDelete", "icon-remove", "删除", perm, "Delete", true)
@Html.ToolButton("btnAllot", "icon-share", "分配用户", perm, "Allot", true)
</div>
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<table id="List"></table>
<script type="text/javascript">
$(function () {
$('#List').datagrid({
url: '@Url.Action("GetList")',
$(window).width() - 10,
methord: 'post',
height: $(window).height() - 35,
fitColumns: true,
sortName: 'CreateTime',
sortOrder: 'desc',
idField: 'Id',
pageSize: 15,
pageList: [15, 20, 30, 40, 50],
pagination: true,
striped: true, //奇偶行是否区分
singleSelect: true,//单选模式
//rownumbers: true,//行号
columns: [[
{ field: 'Id', title: 'ID', 80, hidden: true },
{ field: 'Name', title: '角色名称', 80, sortable: true },
{ field: 'Description', title: '说明', 80, sortable: true },
{ field: 'CreateTime', title: '创建时间', 80, sortable: true },
{ field: 'CreatePerson', title: '创建人', 80, sortable: true },
{ field: 'UserName', title: '属下管理员', 80, sortable: true }
]]
});
});
//ifram 返回
function frameReturnByClose() {
$("#modalwindow").window('close');
}
function frameReturnByReload(flag) {
if (flag)
$("#List").datagrid('load');
else
$("#List").datagrid('reload');
}
function frameReturnByMes(mes) {
$.messageBox5s('提示', mes);
}
$(function () {
$("#btnExport").click(function () {
$("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/SysHelper/ReportControl'></iframe>");
$("#modalwindow").window({ title: '导出', 320, height: 200, iconCls: 'icon-add' }).window('open');
});
$("#btnCreate").click(function () {
$("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/SysRole/Create'></iframe>");
$("#modalwindow").window({ title: '新增', 700, height: 400, iconCls: 'icon-add' }).window('open');
});
$("#btnEdit").click(function () {
var row = $('#List').datagrid('getSelected');
if (row != null) {
$("#modalwindow").html("<iframe width='100%' height='99%' frameborder='0' src='/SysRole/Edit?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
$("#modalwindow").window({ title: '编辑', 700, height: 430, iconCls: 'icon-edit' }).window('open');
} else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
});
$("#btnDetails").click(function () {
var row = $('#List').datagrid('getSelected');
if (row != null) {
$("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0' src='/SysRole/Details?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
$("#modalwindow").window({ title: '详细', 500, height: 300, iconCls: 'icon-details' }).window('open');
} else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
});
$("#btnQuery").click(function () {
var queryStr = $("#txtQuery").val();
if (queryStr == null) {
queryStr = "%";
}
$('#List').datagrid({
url: '@Url.Action("GetList")?queryStr=' + encodeURI(queryStr)
});
});
$("#btnDelete").click(function () {
var row = $('#List').datagrid('getSelected');
if (row != null) {
$.messager.confirm('提示', '@Suggestion.YouWantToDeleteTheSelectedRecords', function (r) {
if (r) {
$.post("@Url.Action("Delete")?id=" + row.Id, function (data) {
if (data.type == 1)
$("#List").datagrid('load');
$.messageBox5s('提示', data.message);
}, "json");
}
});
} else { $.messageBox5s('提示', '@Suggestion.PlaseChooseToOperatingRecords'); }
});
$("#btnAllot").click(function () {
});
});
</script>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<!--自动GRID 从第一次加载与重置窗体大小时候发生的事件:分部视图,当只有一个Grid时且ID为List-->
<script type="text/javascript">
$(function () {
$(window).resize(function () {
$('#List').datagrid('resize', {
$(window).width() - 10,
height: SetGridHeightSub(39)
}).datagrid('resize', {
$(window).width() - 10,
height: SetGridHeightSub(39)
});
});
});
</script>
做了这么久不知道大家有没有发现,层层扣层层,异常捕获,异常记录,日志记录,反转控制,系统的可维护性非常的高,一目了然,这也是发布文章这么久,没人质疑这个架构的所在之处(我们是不是应该自豪一下)