using Microsoft.AspNetCore.Mvc; using ProductionLineMonitor.Application.Services.AdminService; using ProductionLineMonitor.Core.Dtos; using ProductionLineMonitor.Core.Services; using System.Collections.Generic; namespace ProductionLineMonitor.Web.Controllers { public class AdminController : BaseController { private readonly IAdminService _adminService; public AdminController(IAdminService adminService) { _adminService = adminService; } [HttpPost("/Admin/ChangePassword")] public IActionResult ChangePassword([FromBody] UserChangePasswordDto dto) { return Ok(_adminService.ChangePassword(dto)); } [HttpGet("/Admin/User")] public new IActionResult User() { return View(); } [HttpGet("/Admin/User/{id}")] public new IActionResult User([FromRoute] string id) { return Ok(_adminService.GetUserById(id)); } [HttpGet("/Admin/GetUsers")] public IActionResult GetUsers(int pageNumber, int pageSize, string keyword) { pageNumber = pageNumber == 0 ? 1 : pageNumber; pageSize = pageSize == 0 ? 10 : pageSize; keyword ??= ""; return Ok(_adminService.GetUserPageList(pageNumber, pageSize, keyword)); } [HttpPost("/Admin/CreateUser")] public IActionResult CreateUser([FromBody] UserCreateOrUpdateDto dto) { return Ok(_adminService.CreateUser(dto)); } [HttpPost("/Admin/UpdateUser/{id}")] public IActionResult UpdateUser([FromRoute] string id, [FromBody] UserCreateOrUpdateDto dto) { return Ok(_adminService.UpdateUser(id, dto)); } [HttpPost("/Admin/DeleteUser/{id}")] public IActionResult UpdateUser([FromRoute] string id) { return Ok(_adminService.DeleteUser(id)); } [HttpGet("/Admin/Role")] public IActionResult Role() { return View(); } [HttpGet("/Admin/Role/{id}")] public IActionResult GetRoleById([FromRoute] string id) { return Ok(_adminService.GetRoleById(id)); } [HttpGet("/Admin/GetRoles")] public IActionResult GetRoles(int pageNumber, int pageSize, string keyword) { pageNumber = pageNumber == 0 ? 1 : pageNumber; pageSize = pageSize == 0 ? 10 : pageSize; keyword ??= ""; return Ok(_adminService.GetRolePageList(pageNumber, pageSize, keyword)); } [HttpGet("/Admin/GetAllRoles")] public IActionResult GetAllRoles() { return Ok(_adminService.GetAllRoles()); } [HttpPost("/Admin/CreateRole")] public IActionResult CreateRole([FromBody] RoleCreateOrUpdateDto dto) { return Ok(_adminService.CreateRole(dto)); } [HttpPost("/Admin/UpdateRole/{id}")] public IActionResult UpdateRole([FromRoute] string id, [FromBody] RoleCreateOrUpdateDto dto) { return Ok(_adminService.UpdateRole(id, dto)); } [HttpPost("/Admin/DeleteRole/{id}")] public IActionResult DeleteRole([FromRoute] string id) { return Ok(_adminService.DeleteRole(id)); } [HttpGet("/Admin/Menu")] public IActionResult GetMenus() { return Ok(_adminService.GetZNodes()); } [HttpPost("/Admin/SetPermissions/{id}")] public IActionResult SetPermissions([FromRoute] string id, [FromBody] IEnumerable dto) { return Ok(_adminService.SetPermissions(id, dto)); } [HttpPost("/Admin/Permissions/{id}")] public IActionResult GetPermissions([FromRoute] string id) { return Ok(_adminService.GetPermissions(id)); } } }