2018-06-07 00:45:47 +08:00
|
|
|
|
using Bootstrap.Admin.Query;
|
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Bootstrap.Security;
|
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Controllers.Api
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class MenusController : Controller
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public QueryData<BootstrapMenu> Get(QueryMenuOption value)
|
|
|
|
|
{
|
|
|
|
|
return value.RetrieveData(User.Identity.Name);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
[HttpPost]
|
2018-06-07 14:39:45 +08:00
|
|
|
|
public bool Post([FromBody]BootstrapMenu value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
return MenuHelper.SaveMenu(value);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
[HttpDelete]
|
2018-06-08 12:54:05 +08:00
|
|
|
|
public bool Delete([FromBody]IEnumerable<int> value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
return MenuHelper.DeleteMenu(value);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("{id}")]
|
2018-06-07 14:39:45 +08:00
|
|
|
|
public IEnumerable<BootstrapMenu> Post(int id, [FromBody]JObject value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
var ret = new List<BootstrapMenu>();
|
|
|
|
|
dynamic json = value;
|
|
|
|
|
switch ((string)json.type)
|
|
|
|
|
{
|
|
|
|
|
case "role":
|
|
|
|
|
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
|
|
|
|
|
break;
|
|
|
|
|
case "user":
|
|
|
|
|
ret = BootstrapMenu.RetrieveAllMenus(User.Identity.Name).ToList();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut("{id}")]
|
2018-06-07 14:39:45 +08:00
|
|
|
|
public bool Put(int id, [FromBody]JObject value)
|
2018-06-07 00:45:47 +08:00
|
|
|
|
{
|
|
|
|
|
var ret = false;
|
|
|
|
|
dynamic json = value;
|
|
|
|
|
string menuIds = json.menuIds.ToString();
|
|
|
|
|
switch ((string)json.type)
|
|
|
|
|
{
|
|
|
|
|
case "role":
|
|
|
|
|
ret = MenuHelper.SaveMenusByRoleId(id, menuIds);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-25 18:54:20 +08:00
|
|
|
|
}
|