AdminSystemRoleController.cs 3.6 KB

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