AdminController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Microsoft.AspNetCore.Mvc;
  2. using ProductionLineMonitor.Application.Services.AdminService;
  3. using ProductionLineMonitor.Core.Dtos;
  4. using ProductionLineMonitor.Core.Services;
  5. using System.Collections.Generic;
  6. namespace ProductionLineMonitor.Web.Controllers
  7. {
  8. public class AdminController : BaseController
  9. {
  10. private readonly IAdminService _adminService;
  11. public AdminController(IAdminService adminService)
  12. {
  13. _adminService = adminService;
  14. }
  15. [HttpPost("/Admin/ChangePassword")]
  16. public IActionResult ChangePassword([FromBody] UserChangePasswordDto dto)
  17. {
  18. return Ok(_adminService.ChangePassword(dto));
  19. }
  20. [HttpGet("/Admin/User")]
  21. public new IActionResult User()
  22. {
  23. return View();
  24. }
  25. [HttpGet("/Admin/User/{id}")]
  26. public new IActionResult User([FromRoute] string id)
  27. {
  28. return Ok(_adminService.GetUserById(id));
  29. }
  30. [HttpGet("/Admin/GetUsers")]
  31. public IActionResult GetUsers(int pageNumber, int pageSize, string keyword)
  32. {
  33. pageNumber = pageNumber == 0 ? 1 : pageNumber;
  34. pageSize = pageSize == 0 ? 10 : pageSize;
  35. keyword ??= "";
  36. return Ok(_adminService.GetUserPageList(pageNumber, pageSize, keyword));
  37. }
  38. [HttpPost("/Admin/CreateUser")]
  39. public IActionResult CreateUser([FromBody] UserCreateOrUpdateDto dto)
  40. {
  41. return Ok(_adminService.CreateUser(dto));
  42. }
  43. [HttpPost("/Admin/UpdateUser/{id}")]
  44. public IActionResult UpdateUser([FromRoute] string id, [FromBody] UserCreateOrUpdateDto dto)
  45. {
  46. return Ok(_adminService.UpdateUser(id, dto));
  47. }
  48. [HttpPost("/Admin/DeleteUser/{id}")]
  49. public IActionResult UpdateUser([FromRoute] string id)
  50. {
  51. return Ok(_adminService.DeleteUser(id));
  52. }
  53. [HttpGet("/Admin/Role")]
  54. public IActionResult Role()
  55. {
  56. return View();
  57. }
  58. [HttpGet("/Admin/Role/{id}")]
  59. public IActionResult GetRoleById([FromRoute] string id)
  60. {
  61. return Ok(_adminService.GetRoleById(id));
  62. }
  63. [HttpGet("/Admin/GetRoles")]
  64. public IActionResult GetRoles(int pageNumber, int pageSize, string keyword)
  65. {
  66. pageNumber = pageNumber == 0 ? 1 : pageNumber;
  67. pageSize = pageSize == 0 ? 10 : pageSize;
  68. keyword ??= "";
  69. return Ok(_adminService.GetRolePageList(pageNumber, pageSize, keyword));
  70. }
  71. [HttpGet("/Admin/GetAllRoles")]
  72. public IActionResult GetAllRoles()
  73. {
  74. return Ok(_adminService.GetAllRoles());
  75. }
  76. [HttpPost("/Admin/CreateRole")]
  77. public IActionResult CreateRole([FromBody] RoleCreateOrUpdateDto dto)
  78. {
  79. return Ok(_adminService.CreateRole(dto));
  80. }
  81. [HttpPost("/Admin/UpdateRole/{id}")]
  82. public IActionResult UpdateRole([FromRoute] string id, [FromBody] RoleCreateOrUpdateDto dto)
  83. {
  84. return Ok(_adminService.UpdateRole(id, dto));
  85. }
  86. [HttpPost("/Admin/DeleteRole/{id}")]
  87. public IActionResult DeleteRole([FromRoute] string id)
  88. {
  89. return Ok(_adminService.DeleteRole(id));
  90. }
  91. [HttpGet("/Admin/Menu")]
  92. public IActionResult GetMenus()
  93. {
  94. return Ok(_adminService.GetZNodes());
  95. }
  96. [HttpPost("/Admin/SetPermissions/{id}")]
  97. public IActionResult SetPermissions([FromRoute] string id, [FromBody] IEnumerable<MenuDto> dto)
  98. {
  99. return Ok(_adminService.SetPermissions(id, dto));
  100. }
  101. [HttpPost("/Admin/Permissions/{id}")]
  102. public IActionResult GetPermissions([FromRoute] string id)
  103. {
  104. return Ok(_adminService.GetPermissions(id));
  105. }
  106. }
  107. }