BootstrapAdmin/Bootstrap.Admin/Controllers/Api/MenusController.cs

85 lines
2.6 KiB
C#
Raw Normal View History

using Bootstrap.Admin.Query;
2018-06-07 00:45:47 +08:00
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
///
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class MenusController : ControllerBase
2018-06-07 00:45:47 +08:00
{
/// <summary>
/// 获得所有菜单列表调用
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<object> Get([FromQuery]QueryMenuOption value)
2018-06-07 00:45:47 +08:00
{
return value.RetrieveData(User.Identity.Name);
}
2018-06-07 00:45:47 +08:00
/// <summary>
/// 保存菜单调用
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="value"></param>
[HttpPost]
[ButtonAuthorize(Url = "~/Admin/Menus", Auth = "add,edit")]
2018-06-07 14:39:45 +08:00
public bool Post([FromBody]BootstrapMenu value)
2018-06-07 00:45:47 +08:00
{
return MenuHelper.Save(value);
2018-06-07 00:45:47 +08:00
}
2018-06-07 00:45:47 +08:00
/// <summary>
/// 删除菜单调用
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="value"></param>
[HttpDelete]
[ButtonAuthorize(Url = "~/Admin/Menus", Auth = "del")]
2018-10-30 13:07:29 +08:00
public bool Delete([FromBody]IEnumerable<string> value)
2018-06-07 00:45:47 +08:00
{
return MenuHelper.Delete(value);
2018-06-07 00:45:47 +08:00
}
2018-06-07 00:45:47 +08:00
/// <summary>
/// 角色管理菜单授权按钮调用
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="id">角色ID</param>
/// <param name="type">type=role时角色管理菜单授权调用type=user时菜单管理编辑页面父类菜单按钮调用</param>
2018-06-07 00:45:47 +08:00
/// <returns></returns>
[HttpPost("{id}")]
public IEnumerable<object> Post(string id, [FromQuery]string type)
2018-06-07 00:45:47 +08:00
{
IEnumerable<object> ret = new List<object>();
switch (type)
2018-06-07 00:45:47 +08:00
{
case "role":
ret = MenuHelper.RetrieveMenusByRoleId(id);
2018-06-07 00:45:47 +08:00
break;
case "user":
ret = MenuHelper.RetrieveMenus(User.Identity.Name);
2018-06-07 00:45:47 +08:00
break;
}
return ret;
}
2018-06-07 00:45:47 +08:00
/// <summary>
/// 角色管理菜单授权保存按钮调用
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="id">菜单ID</param>
/// <param name="roleIds">角色ID集合</param>
2018-06-07 00:45:47 +08:00
/// <returns></returns>
[HttpPut("{id}")]
[ButtonAuthorize(Url = "~/Admin/Menus", Auth = "assignRole")]
public bool Put(string id, [FromBody]IEnumerable<string> roleIds)
2018-06-07 00:45:47 +08:00
{
return RoleHelper.SavaByMenuId(id, roleIds);
2018-06-07 00:45:47 +08:00
}
}
}