AdminSystemRoleController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Request.Menu;
  4. using GxPress.Request.Role;
  5. using GxPress.Result.SystemRole;
  6. using GxPress.Service.Interface.Role;
  7. using Microsoft.AspNetCore.Authorization;
  8. using Microsoft.AspNetCore.Mvc;
  9. namespace GxPress.Api.AdminControllers
  10. {
  11. [Route("api/admin/system-role")]
  12. [ApiController]
  13. [Authorize]
  14. public class AdminSystemRoleController : Controller
  15. {
  16. private readonly IRoleService roleService;
  17. public AdminSystemRoleController(IRoleService roleService)
  18. {
  19. this.roleService = roleService;
  20. }
  21. /// <summary>
  22. /// 添加权限菜单关联
  23. /// </summary>
  24. /// <param name="models"></param>
  25. /// <returns></returns>
  26. [HttpPost("add-role-menus")]
  27. public async Task<bool> InsertSystemRoleMenusAsync(SystemRoleMenusInRequest models)
  28. {
  29. return await roleService.InsertSystemRoleMenusAsync(models);
  30. }
  31. /// <summary>
  32. /// 添加 角色和权限
  33. /// </summary>
  34. /// <param name="request"></param>
  35. /// <returns></returns>
  36. [HttpPost("add-role")]
  37. public async Task<bool> InsertSystemRoleAsync(RoleInRequest request)
  38. {
  39. return await roleService.InsertSystemRoleAsync(request);
  40. }
  41. /// <summary>
  42. /// 获取所有角色
  43. /// </summary>
  44. /// <returns></returns>
  45. [HttpGet("role")]
  46. public async Task<List<SystemRoleResult>> GetSystemRoleAllAsync()
  47. {
  48. return await roleService.GetSystemRoleAllAsync();
  49. }
  50. /// <summary>
  51. /// 修改角色 权限
  52. /// </summary>
  53. /// <param name="request"></param>
  54. /// <returns></returns>
  55. [HttpPut("update-role")]
  56. public async Task<bool> UpdateSystemRoleAsync(RoleInRequest request)
  57. {
  58. return await roleService.UpdateSystemRoleAsync(request);
  59. }
  60. /// <summary>
  61. /// 删除权限
  62. /// </summary>
  63. /// <param name="id"></param>
  64. /// <returns></returns>
  65. [HttpDelete("role/{id}")]
  66. public async Task<bool> DeleteSystemRoleAsync(int id)
  67. {
  68. return await roleService.DeleteSystemRoleAsync(id);
  69. }
  70. /// <summary>
  71. /// 添加菜单
  72. /// </summary>
  73. /// <param name="model"></param>
  74. /// <returns></returns>
  75. [HttpPost("add-menu")]
  76. public async Task<bool> InsertMenusAsync([FromBody] List<MenuInRequest> model)
  77. {
  78. return await roleService.InsertMenusAsync(model);
  79. }
  80. /// <summary>
  81. /// 修改菜单
  82. /// </summary>
  83. /// <param name="model"></param>
  84. /// <returns></returns>
  85. [HttpPut("update-menu")]
  86. public async Task<bool> UpdateMenusAsync(Entity.Menus.Menus model)
  87. {
  88. return await roleService.UpdateMenusAsync(model);
  89. }
  90. /// <summary>
  91. /// 删除菜单
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <returns></returns>
  95. [HttpDelete("delete-menu")]
  96. public async Task<bool> DeleteMenusAsync(int id)
  97. {
  98. return await roleService.DeleteMenusAsync(id);
  99. }
  100. /// <summary>
  101. /// 根据权限ID获取菜单
  102. /// </summary>
  103. /// <param name="roleId"></param>
  104. /// <returns></returns>
  105. [HttpGet("menus/{roid}")]
  106. public async Task<List<MenuInResult>> GetMenusAllAsync(int roleId)
  107. {
  108. //获取
  109. return await roleService.GetMenusAllAsync(roleId);
  110. }
  111. /// <summary>
  112. /// 获取所有菜单
  113. /// </summary>
  114. /// <returns></returns>
  115. [HttpGet("menus")]
  116. public async Task<IEnumerable<Entity.Menus.Menus>> GetMenusAllAsync()
  117. {
  118. return await roleService.GetMenusAllAsync();
  119. }
  120. }
  121. }