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; default: break; } return ret.Select(m => new { m.Id, m.Checked, m.RoleName, m.Description }); } /// /// 保存角色 /// /// 用户ID/部门ID/菜单ID /// 选中的角色ID集合 /// type=menu时,菜单维护页面对角色授权弹框保存按钮调用 /// [HttpPut("{id}")] public bool Put(string id, [FromBody]IEnumerable roleIds, [FromQuery]string type) { var ret = false; switch (type) { case "user": ret = RoleHelper.SaveByUserId(id, roleIds); break; case "group": ret = RoleHelper.SaveByGroupId(id, roleIds); break; case "menu": ret = RoleHelper.SavaByMenuId(id, roleIds); break; default: break; } return ret; } /// /// /// /// [HttpPost] public bool Post([FromBody]Role value) { return RoleHelper.Save(value); } /// /// /// /// [HttpDelete] public bool Delete([FromBody]IEnumerable value) { return RoleHelper.Delete(value); } } }