using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
///
///
///
[Route("api/[controller]")]
public class MenusController : Controller
{
///
/// 获得所有菜单列表调用
///
///
///
[HttpGet]
public QueryData Get(QueryMenuOption value)
{
return value.RetrieveData(User.Identity.Name);
}
///
/// 保存菜单调用
///
///
[HttpPost]
public bool Post([FromBody]BootstrapMenu value)
{
return MenuHelper.SaveMenu(value);
}
///
/// 删除菜单调用
///
///
[HttpDelete]
public bool Delete([FromBody]IEnumerable value)
{
return MenuHelper.DeleteMenu(value);
}
///
///
///
///
///
///
[HttpPost("{id}")]
public IEnumerable Post(int id, [FromQuery]string type)
{
var ret = new List();
switch (type)
{
case "role":
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
break;
case "user":
ret = MenuHelper.RetrieveAllMenus(User.Identity.Name).ToList();
break;
default:
break;
}
return ret;
}
///
/// 角色管理页面分配菜单时调用
///
/// 角色ID
/// 菜单ID集合
///
[HttpPut("{id}")]
public bool Put(int id, [FromBody]IEnumerable value)
{
return MenuHelper.SaveMenusByRoleId(id, value);
}
}
}