using Mini.Common; using Air.Model.AirAdminViewModel; using System; using System.Collections.Generic; using Mini.Services.Bas; using Mini.Web.WebHelper; using Microsoft.AspNetCore.Mvc; namespace Mini.Web.Areas.Admin.Controllers { public class RightGroupController : BaseController { ValidationErrors errors = new ValidationErrors(); private readonly IBasRightGroupService _basRightGroupService; public RightGroupController(IBasRightGroupService basRightGroupService) { this._basRightGroupService = basRightGroupService; } #region 首页 [AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)] [Area("Admin")] 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_权限结构管理)] [Area("Admin")] public JsonResult GetTopGroupTree() { return Json(_basRightGroupService.GetTopTreeList()); } /// /// 获取子数据 /// /// /// [AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)] [Area("Admin")] public JsonResult GetGroupTree(int id) { return Json(_basRightGroupService.GetNodeTreeList(id)); } /// /// 获取所有的权限组结构(不包括right) /// /// [Area("Admin")] public JsonResult GetAllGroupTree() { return Json(_basRightGroupService.GetAllTreeList()); } /// /// 获取所有的权限组结构(包括了right) /// /// [Area("Admin")] public JsonResult GetRightTreeList(string isSelect = "false") { bool _isSelect = Convert.ToBoolean(isSelect); return Json(_basRightGroupService.GetRightTreeList(_isSelect)); } #endregion #region 详细 [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Details)] [Area("Admin")] public ActionResult Details(int? id) { ViewBag.notId = Request.Query["notId"].ToString(); var model = new Bas_RightGroupModel(); if (id.HasValue) model = _basRightGroupService.Get(id.Value); return View(model); } #endregion #region 编辑 [HttpGet] [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Edit)] [Area("Admin")] public ActionResult Edit(int? id, int? fid) { ViewBag.notId = Request.Query["notId"].ToString(); var model = new Bas_RightGroupModel(); if (id.HasValue) model = _basRightGroupService.Get(id.Value); model.ParentId = model.PkId == 0 ? fid.Value : model.ParentId; return View(model); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Edit)] [Area("Admin")] public JsonResult Edit(Bas_RightGroupModel model) { //if (!ModelState.IsValid) // return JsonHandler.ValidateFailMessage(); if (model.PkId == 0) { model.CTime = DateTime.Now; _basRightGroupService.Create(model); return JsonHandler.InsertMessage(errors, true); } else { _basRightGroupService.Update(model); return JsonHandler.UpdateMessage(errors, true); } } #endregion #region 删除 [AuthorizeToolBar(InitRights.CONST_权限结构管理, InitToolBar.CONST_Delete)] [Area("Admin")] public JsonResult Delete(Bas_RightGroupModel model) { if (model.PkId <= 0) { return JsonHandler.ManageMessage("参数错误", false); } _basRightGroupService.Delete(model); return JsonHandler.DeleteMessage(errors, true); } #endregion } }