using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
///
///
///
[Route("api/[controller]")]
[ApiController]
public class RolesController : ControllerBase
{
///
///
///
///
///
[HttpGet]
public QueryData Get([FromQuery]QueryRoleOption value)
{
return value.RetrieveData();
}
///
/// 通过指定用户ID/部门ID/菜单ID获得所有角色集合,已经授权的有checked标记
///
/// 用户ID/部门ID/菜单ID
/// 类型
///
[HttpPost("{id}")]
public IEnumerable Post(string id, [FromQuery]string type)
{
IEnumerable ret = new List();
switch (type)
{
case "user":
ret = RoleHelper.RetrievesByUserId(id);
break;
case "group":
ret = RoleHelper.RetrievesByGroupId(id);
break;
case "menu":
ret = RoleHelper.RetrievesByMenuId(id);
break;
}
return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description });
}
///
/// 保存角色
///
/// 角色ID
/// 选中的ID集合
/// type=menu时,菜单维护页面对角色授权弹框保存按钮调用
///
[HttpPut("{id}")]
[ButtonAuthorize(Url = "~/Admin/Roles", Auth = "assignUser,assignGroup,assignMenu,assignApp")]
public bool Put(string id, [FromBody]IEnumerable values, [FromQuery]string type)
{
var ret = false;
switch (type)
{
case "user":
ret = UserHelper.SaveByRoleId(id, values);
break;
case "group":
ret = GroupHelper.SaveByRoleId(id, values);
break;
case "menu":
ret = MenuHelper.SaveMenusByRoleId(id, values);
break;
case "app":
ret = AppHelper.SaveByRoleId(id, values);
break;
}
return ret;
}
///
///
///
///
[HttpPost]
[ButtonAuthorize(Url = "~/Admin/Roles", Auth = "add,edit")]
public bool Post([FromBody]Role value)
{
return RoleHelper.Save(value);
}
///
///
///
///
[HttpDelete]
[ButtonAuthorize(Url = "~/Admin/Roles", Auth = "del")]
public bool Delete([FromBody]IEnumerable value)
{
return RoleHelper.Delete(value);
}
}
}