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

155 lines
5.5 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 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<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_权限结构管理)]
[Area("Admin")]
public JsonResult GetTopGroupTree()
{
return Json(_basRightGroupService.GetTopTreeList());
}
/// <summary>
/// 获取子数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_权限结构管理)]
[Area("Admin")]
public JsonResult GetGroupTree(int id)
{
return Json(_basRightGroupService.GetNodeTreeList(id));
}
/// <summary>
/// 获取所有的权限组结构不包括right
/// </summary>
/// <returns></returns>
[Area("Admin")]
public JsonResult GetAllGroupTree()
{
return Json(_basRightGroupService.GetAllTreeList());
}
/// <summary>
/// 获取所有的权限组结构包括了right
/// </summary>
/// <returns></returns>
[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
}
}