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.IBLL.Util; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Controllers.Base { public class RightGroupController : BaseController { private IBAS_RIGHTGROUP rightGroupBiz; private IBAS_RIGHTGROUP_Q rightGroupBiz_Q; private IBAS_ROLERIGHTRESOURCE_Q roleRightResourceBiz_Q; private ICACHE_Q _cache; ValidationErrors errors = new ValidationErrors(); public RightGroupController(IBAS_RIGHTGROUP _rightGroupBiz, IBAS_RIGHTGROUP_Q _rightGroupBiz_Q, IBAS_ROLERIGHTRESOURCE_Q _roleRightResourceBiz_Q, ICACHE_Q cache) { this.rightGroupBiz = _rightGroupBiz; this.rightGroupBiz_Q = _rightGroupBiz_Q; this.roleRightResourceBiz_Q = _roleRightResourceBiz_Q; this._cache = cache; } #region 首页 [AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)] public ActionResult Index() { //ToolBar ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.权限结构管理, userRightId); List listBtn = new List(toolbtn); List Buttons = new List(); Buttons.Add("Other1"); Buttons.Add("Other2"); Buttons.Add("Other5"); Buttons.AddRange(listBtn); tool.AllowButton(Buttons.ToArray()); // tool.AllowButton("Other1", "Other2", "Other5", "Other3", "Other4", "Edit", "Details", "Delete"); tool.AddOtherButton("Other1", "展开全部", "icon-flag", "ExpandAll_Click", true); tool.AddOtherButton("Other2", "折叠全部", "icon-show", "CollapseAll_Click", true); tool.AddOtherButton("Other3", "新增组", "icon-add", "CreateGroup_Click", true); tool.AddOtherButton("Other4", "新增资源", "icon-add", "CreateRight_Click", true); tool.AddOtherButton("Other5", "重新加载", "icon-reload", "Reload_Click", true); tool.AddOtherButton("Other6", "更新权限", "icon-reload", "RightLoad_Click", true); ViewBag.ToolBar = tool; return View(); } #endregion #region 树形数据 /// /// 获取顶端数据 /// /// [AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)] public JsonResult GetTopGroupTree() { return Json(rightGroupBiz_Q.GetTopTreeList(), JsonRequestBehavior.AllowGet); } /// /// 获取子数据 /// /// /// [AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)] public JsonResult GetGroupTree(string id) { decimal fid = 0; if (!string.IsNullOrWhiteSpace(id)) decimal.TryParse(id, out fid); return Json(rightGroupBiz_Q.GetNodeTreeList(fid), JsonRequestBehavior.AllowGet); } /// /// 获取所有的权限组结构(不包括right) /// /// public JsonResult GetAllGroupTree() { return Json(rightGroupBiz_Q.GetAllTreeList(), JsonRequestBehavior.AllowGet); } /// /// 获取所有的权限组结构(包括了right) /// /// public JsonResult GetRightTreeList(string isSelect = "false") { bool _isSelect = Convert.ToBoolean(isSelect); return Json(rightGroupBiz_Q.GetRightTreeList(_isSelect), JsonRequestBehavior.AllowGet); } #endregion #region 详细 [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Details)] public ActionResult Details(string id) { WX.CRM.Model.Entity.BAS_RIGHTGROUP model = new WX.CRM.Model.Entity.BAS_RIGHTGROUP(); if (id != null) model = rightGroupBiz_Q.GetModel(Convert.ToDecimal(id)); return View(model); } #endregion #region 编辑 [HttpGet] [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Edit)] public ActionResult Edit(string id) { WX.CRM.Model.Entity.BAS_RIGHTGROUP model = new WX.CRM.Model.Entity.BAS_RIGHTGROUP(); if (id != null) model = rightGroupBiz_Q.GetModel(Convert.ToDecimal(id)); string fid = Request.QueryString["fid"]; model.PARENTID = Convert.ToDecimal((model.PKID == 0 ? fid : model.PARENTID.ToString())); return View(model); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Edit)] public JsonResult Edit(WX.CRM.Model.Entity.BAS_RIGHTGROUP model) { if (!ModelState.IsValid) return JsonHandler.ValidateFailMessage(); if (model.PKID == 0) { model.CTIME = DateTime.Now; bool result = rightGroupBiz.Create(ref errors, model); return JsonHandler.InsertMessage(errors, result); } else { bool result = rightGroupBiz.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 = rightGroupBiz.Delete(ref errors, Convert.ToDecimal(id)); return JsonHandler.DeleteMessage(errors, result); } #endregion #region 查看角色 [HttpPost] public JsonResult GetHasRoles(string rightId) { var roleId = roleRightResourceBiz_Q.IncRolesList(rightId); var roleList = _cache.GetList_Role().Where(p => roleId.Contains(p.ROLEID)); var roleName = string.Empty; foreach (var role in roleList) { roleName += "【" + role.RNAME + "】"; } return Json(new { data = roleName }, JsonRequestBehavior.AllowGet); } #endregion } }