Mini.Crm/Mini.Web/Areas/Admin/Controllers/RoleRightResourceController.cs

86 lines
3.7 KiB
C#

using Mini.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using Mini.Web.WebHelper;
using Microsoft.AspNetCore.Mvc;
using Mini.Services.Bas;
namespace Mini.Web.Areas.Admin.Controllers
{
public class RoleRightResourceController : BaseController
{
ValidationErrors errors = new ValidationErrors();
private readonly IBasRoleRightResourceService _basRoleRightResourceService;
private readonly IBasRightService _basRightService;
private readonly IBasRightToolButtonService _basRightToolButtonService;
public RoleRightResourceController(IBasRoleRightResourceService basRoleRightResourceService, IBasRightService basRightService, IBasRightToolButtonService basRightToolButtonService)
{
this._basRoleRightResourceService = basRoleRightResourceService;
this._basRightService = basRightService;
this._basRightToolButtonService = basRightToolButtonService;
}
#region
[AuthorizeRedirect(Roles = InitRights.CONST_角色权限管理)]
[Area("Admin")]
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("Other6");
Buttons.Add("Other5");
Buttons.Add("Other4");
Buttons.AddRange(listBtn);
tool.AllowButton(Buttons.ToArray());
// tool.AllowButton("Other1", "Other2", "Other3", "Other4", "Other5", "Other6");
tool.AddOtherButton("Other6", "展开权限", "icon-flag", "ExpandAll_Click", true);
tool.AddOtherButton("Other5", "折叠权限", "icon-show", "CollapseAll_Click", true);
tool.AddOtherButton("Other4", "刷新", "icon-reload", "Reload_Click", true);
tool.AddOtherButton("Other1", "保存", "icon-save", "Save_Click", true);
tool.AddOtherButton("Other2", "新增角色", "icon-add", "AddRole_Click", true);
tool.AddOtherButton("Other3", "更新权限", "icon-reload", "RightLoad_Click", true);
ViewBag.ToolBar = tool;
return View();
}
#endregion
#region
/// <summary>
/// 获取角色权限
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_角色权限管理)]
[Area("Admin")]
public JsonResult GetBas_RoleRight(int id)
{
return Json(_basRoleRightResourceService.GetObjectByRoleId(id));
}
#endregion
#region
//[AuthorizeToolBar(InitRights.CONST_角色权限管理, InitToolBar.CONST_Other1)]
[Area("Admin")]
public JsonResult Save(int roleId, string rightIds)
{
if (roleId <= 0 || string.IsNullOrWhiteSpace(rightIds))
return JsonHandler.ManageMessage("参数不对!", false);
bool result = _basRoleRightResourceService.Save(roleId, rightIds, UserId);
return JsonHandler.UpdateMessage(errors, result);
}
#endregion
#region ToolButton
//[AuthorizeToolBar(InitRights.CONST_角色权限管理, InitToolBar.CONST_Other1)]
[Area("Admin")]
public ActionResult SyncRightAndToolBar()
{
bool result = new InitRightsToData(_basRightService, _basRightToolButtonService).Insert(ref errors);
return JsonHandler.InsertMessage(errors, result);
}
#endregion
}
}