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

170 lines
6.6 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 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<string> listBtn = new List<string>(toolbtn);
List<string> Buttons = new List<string>();
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
/// <summary>
/// 获取顶端数据
/// </summary>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)]
public JsonResult GetTopGroupTree()
{
return Json(rightGroupBiz_Q.GetTopTreeList(), JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 获取子数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[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);
}
/// <summary>
/// 获取所有的权限组结构不包括right
/// </summary>
/// <returns></returns>
public JsonResult GetAllGroupTree()
{
return Json(rightGroupBiz_Q.GetAllTreeList(), JsonRequestBehavior.AllowGet);
}
/// <summary>
/// 获取所有的权限组结构包括了right
/// </summary>
/// <returns></returns>
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
}
}