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

97 lines
3.0 KiB
C#
Raw Normal View History

2018-06-07 00:45:47 +08:00
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
{
/// <summary>
///
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class RolesController : ControllerBase
2018-06-07 00:45:47 +08:00
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<object> Get([FromQuery]QueryRoleOption value)
2018-06-07 00:45:47 +08:00
{
return value.RetrieveData();
}
/// <summary>
/// 通过指定用户ID/部门ID/菜单ID获得所有角色集合已经授权的有checked标记
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="id">用户ID/部门ID/菜单ID</param>
/// <param name="type">类型</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<Role> ret = new List<Role>();
switch (type)
2018-06-07 00:45:47 +08:00
{
case "user":
ret = RoleHelper.RetrievesByUserId(id);
2018-06-07 00:45:47 +08:00
break;
case "group":
ret = RoleHelper.RetrievesByGroupId(id);
2018-06-07 00:45:47 +08:00
break;
case "menu":
ret = RoleHelper.RetrievesByMenuId(id);
2018-06-07 00:45:47 +08:00
break;
}
return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description });
2018-06-07 00:45:47 +08:00
}
/// <summary>
/// 保存角色
2018-06-07 00:45:47 +08:00
/// </summary>
/// <param name="id">用户ID/部门ID/菜单ID</param>
/// <param name="roleIds">选中的角色ID集合</param>
/// <param name="type">type=menu时菜单维护页面对角色授权弹框保存按钮调用</param>
2018-06-07 00:45:47 +08:00
/// <returns></returns>
[HttpPut("{id}")]
2018-10-30 13:07:29 +08:00
public bool Put(string id, [FromBody]IEnumerable<string> roleIds, [FromQuery]string type)
2018-06-07 00:45:47 +08:00
{
var ret = false;
switch (type)
2018-06-07 00:45:47 +08:00
{
case "user":
ret = RoleHelper.SaveByUserId(id, roleIds);
2018-06-07 00:45:47 +08:00
break;
case "group":
ret = RoleHelper.SaveByGroupId(id, roleIds);
2018-06-07 00:45:47 +08:00
break;
case "menu":
ret = RoleHelper.SavaByMenuId(id, roleIds);
2018-06-07 00:45:47 +08:00
break;
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpPost]
2018-06-07 14:39:45 +08:00
public bool Post([FromBody]Role value)
2018-06-07 00:45:47 +08:00
{
return RoleHelper.Save(value);
2018-06-07 00:45:47 +08:00
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
[HttpDelete]
2018-10-30 13:07:29 +08:00
public bool Delete([FromBody]IEnumerable<string> value)
2018-06-07 00:45:47 +08:00
{
return RoleHelper.Delete(value);
2018-06-07 00:45:47 +08:00
}
}
}