TG.WXCRM.V4/WEB/Controllers/Base/RoleController.cs

325 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.Base;
using WX.CRM.Model.Entity;
using WX.CRM.Model.MAP;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.Base
{
public class RoleController : BaseController
{
private IBAS_ROLE roleBiz;
private IBAS_ROLE_Q roleBiz_Q;
[Inject]
public IBAS_RIGHT_LEVEL bas_right_level { get; set; }
ValidationErrors errors = new ValidationErrors();
public RoleController(IBAS_ROLE _roleBiz, IBAS_ROLE_Q _roleBiz_Q)
{
this.roleBiz = _roleBiz;
this.roleBiz_Q = _roleBiz_Q;
}
#region
[AuthorizeRedirect(Roles = InitRights.CONST_角色管理)]
public ActionResult Index()
{
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
// tool.AllowButton("Create", "Edit", "Details", "Other1", "Delete");
tool.AddOtherButton("Other1", "更新顺序", "icon-reload", "UpdateSort_Click", true);
tool.AddOtherButton("Other2", "设置页面等级", "icon-edit", "SetDengji_Click", true);
ViewBag.ToolBar = tool;
//DataGrid
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("ROLEID", "10%", "角色ID");
tab.AddHeadCol("RNAME", "", "角色名称 ");
tab.AddHeadCol("CODE", "", "编码");
tab.AddHeadCol("REMARK", "", "说明");
tab.AddHeadCol("SORTID", "10%", "排序");
//tab.AddHeadCol("LEVEL", "10%", "等级");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
return View();
}
/// <summary>
/// 获取全部数据列表
/// </summary>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_角色管理)]
public JsonResult GetHtmlList(string columns)
{
List<WX.CRM.Model.Entity.BAS_ROLE> modelist = roleBiz_Q.GetList();
Table table = new Table(columns, true);
foreach (WX.CRM.Model.Entity.BAS_ROLE model in modelist)
{
table.AddCol(model.ROLEID);
table.AddCol("text-align:left;padding-left:20px;", "", model.RNAME);
table.AddCol("text-align:left;padding-left:20px;", "", model.CODE);
table.AddCol(model.REMARK);
table.AddCol(string.Format("<input type='text' value='{0}' oldvalue='{0}' roleId='{1}' style='width:40px;'/>", model.SORTID, model.ROLEID));
//table.AddCol("");
table.AddRow();
}
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other2)]
public ActionResult RoleLevel()
{
//ToolBar
//ToolBar tool = new ToolBar();
//string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.角色管理, userRightId);
//tool.AllowButton(toolbtn);
//// tool.AllowButton("Create", "Edit", "Details", "Other1", "Delete");
//tool.AddOtherButton("Other1", "更新顺序", "icon-reload", "UpdateSort_Click", true);
//tool.AddOtherButton("Other2", "设置页面等级", "icon-edit", "SetDengji_Click", true);
//ViewBag.ToolBar = tool;
//DataGrid
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHiddenHeadCol("PKID", "");
tab.AddHeadCol("RIGHTID", "7%", "权限ID ");
tab.AddHeadCol("RNAME", "8%", "权限名称");
tab.AddHeadCol("ROLECODE", "10%", "角色编码");
tab.AddHeadCol("REMARKS", "10%", "备注");
tab.AddHeadCol("STATUS", "10%", "状态");
tab.AddHeadCol("CTIME", "10%", "创建时间");
tab.AddHeadCol("LEVEL", "", "等级");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetTable();
return View();
}
/// <summary>
/// 获取全部数据列表
/// </summary>
/// <returns></returns>
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other2)]
public JsonResult GetRoleLevelHtmlList(string columns, string rightcode, string rolecode)
{
List<Bas_Right_Level_Map> modelist = bas_right_level.GetList(rightcode, rolecode);
Table table = new Table(columns, true);
foreach (Bas_Right_Level_Map model in modelist)
{
table.AddHiddenCol(model.PKID);
table.AddCol("text-align:left;padding-left:20px;", "", model.RIGHTID);
table.AddCol("text-align:left;padding-left:20px;", "", model.RNAME);
table.AddCol("text-align:left;padding-left:20px;", "", model.ROLECODE);
table.AddCol(model.REMARKS);
if (model.STATUS == 1)
{
table.AddCol("<span stle='color:#2e9821;'>正常</span>");
}
else
{
table.AddCol("<span stle='color:#f70a0a;'>禁用</span>");
}
table.AddCol(model.CTIME.ToUnityString(1));
if (model.Detail.Count > 0)
{
string dptname = "营业部:";
List<Bas_Right_Level_Detail_Map> dpt = model.Detail.Where(m => m.TYPEID == 2).ToList();
foreach (var item in dpt)
{
dptname += string.Format("\"{0}\"", item.deptName);
}
string gname = "销售组:";
List<Bas_Right_Level_Detail_Map> gp = model.Detail.Where(m => m.TYPEID == 1).ToList();
foreach (var item in gp)
{
gname += string.Format("\"{0}-{1}\"", item.deptName, item.groupName);
}
string newstr = string.Empty;
if (dpt.Count > 0)
{
newstr += dptname;
}
if (gp.Count > 0)
{
if (!string.IsNullOrEmpty(newstr))
newstr += "<br/>";
newstr += gname;
}
table.AddCol("text-align:left;padding-left:20px;", "", newstr);
}
table.AddRow();
}
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#region
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other2)]
public ActionResult LevelEdit(decimal? id, string rolecode)
{
BAS_RIGHT_LEVEL model = new BAS_RIGHT_LEVEL() { ROLECODE = rolecode, PKID = 0, STATUS = 1 };
if (id.HasValue)
{
model = bas_right_level.GetModel(id.Value);
List<BAS_RIGHT_LEVEL_DETAIL> detailList = bas_right_level.GetDetailModel(id.Value);
ViewBag.detail = detailList;
}
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other2)]
public JsonResult LevelEdiSavet(Bas_Right_Level_Save model)
{
BAS_RIGHT_LEVEL main = new BAS_RIGHT_LEVEL()
{
PKID = model.PKID,
REMARKS = model.REMARKS,
RIGHTID = model.RIGHTID,
RNAME = model.RNAME,
ROLECODE = model.ROLECODE,
STATUS = model.STATUS
};
List<BAS_RIGHT_LEVEL_DETAIL> list = JsonHelper.JsonDivertToObj<List<BAS_RIGHT_LEVEL_DETAIL>>(model.Detail);
if (model.PKID == 0)
{
main.CTIME = DateTime.Now;
bool result = bas_right_level.Create(ref errors, main, list);
CacheHelper.Remove("cache_BAS_RIGHT_LEVEL_DETAIL");
return JsonHandler.InsertMessage(errors, result);
}
else
{
bool result = bas_right_level.Update(ref errors, main, list);
CacheHelper.Remove("cache_BAS_RIGHT_LEVEL_DETAIL");
return JsonHandler.UpdateMessage(errors, result);
}
}
#endregion
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other2)]
public JsonResult LevelDelete(decimal id)
{
bool result = bas_right_level.Delete(ref errors, id);
CacheHelper.Remove("cache_BAS_RIGHT_LEVEL_DETAIL");
return JsonHandler.DeleteMessage(errors, result);
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Details)]
public ActionResult Details(string id)
{
if (string.IsNullOrWhiteSpace(id))
return View(new WX.CRM.Model.Entity.BAS_ROLE());
else
return View(roleBiz_Q.GetModel(Convert.ToDecimal(id)));
}
#endregion
#region
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Edit)]
public ActionResult Edit(string id)
{
decimal inid = id == null ? 0 : Convert.ToDecimal(id);
WX.CRM.Model.Entity.BAS_ROLE model = new WX.CRM.Model.Entity.BAS_ROLE();
if (inid != 0)
model = roleBiz_Q.GetModel(inid);
return View(model);
}
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Edit)]
public JsonResult Edit(WX.CRM.Model.Entity.BAS_ROLE model)
{
if (!ModelState.IsValid)
return JsonHandler.ValidateFailMessage();
if (model.ROLEID == 0)
{
model.CTIME = DateTime.Now;
model.CREATEUSER = UserId;
bool result = roleBiz.Create(ref errors, model);
return JsonHandler.InsertMessage(errors, result);
}
else
{
model.UTIME = DateTime.Now;
model.UPDATEUSER = UserId;
bool result = roleBiz.Update(ref errors, model);
return JsonHandler.UpdateMessage(errors, result);
}
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Delete)]
public JsonResult Delete(string id)
{
if (string.IsNullOrWhiteSpace(id))
return JsonHandler.ManageMessage("参数不对!", false);
bool result = roleBiz.Delete(ref errors, Convert.ToDecimal(id));
return JsonHandler.DeleteMessage(errors, result);
}
#endregion
#region
/// <summary>
/// 更新列表数据排序
/// </summary>
/// <returns></returns>
[AuthorizeToolBar(InitRights.CONST_角色管理, InitToolBar.CONST_Other1)]
public JsonResult Sort(string roleIds, string sortIds)
{
bool result = roleBiz.Sort(ref errors, roleIds, sortIds);
return JsonHandler.ManageMessage(errors, result);
}
#endregion
#region
[HttpPost]
/// <summary>
/// 获取角色树形
/// </summary>
/// <returns></returns>
public JsonResult GetRoleTree()
{
return Json(roleBiz_Q.GetRoleTree(), JsonRequestBehavior.AllowGet);
}
#endregion
#region
[HttpPost]
/// <summary>
/// 获取角色树形
/// </summary>
/// <returns></returns>
public JsonResult GetRoleAllTree()
{
List<object> obj = new List<object>() { new { id = 0, text = "所有角色", iconCls = " icon-group", children = roleBiz_Q.GetRoleTree() } };
return Json(obj, JsonRequestBehavior.AllowGet);
}
#endregion
}
}