UserController.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Http;
  3. using Microsoft.AspNetCore.Mvc;
  4. using MTWorkHR.Application.Filters;
  5. using MTWorkHR.Application.Identity;
  6. using MTWorkHR.Application.Models;
  7. using MTWorkHR.Identity.Services;
  8. namespace MTWorkHR.API.Controllers
  9. {
  10. [Route("api/[controller]")]
  11. [ApiController]
  12. [AppAuthorize]
  13. public class UserController : ControllerBase
  14. {
  15. private readonly IUserService _userService;
  16. public UserController(IUserService userService)
  17. {
  18. this._userService = userService;
  19. }
  20. [HttpGet("GetAll")]
  21. public async Task<ActionResult<List<UserAllDto>>> GetAll([FromQuery] UserPagingInputDto pagingInput)
  22. {
  23. return Ok( await _userService.GetAll(pagingInput));
  24. }
  25. [HttpGet("GetAllCompanyEmployees")]
  26. public async Task<ActionResult<List<UserDto>>> GetAllCompanyEmployees()
  27. {
  28. return Ok(await _userService.GetAllCompanyEmployees());
  29. }
  30. [HttpGet("Get")]
  31. public async Task<ActionResult<UserDto>> Get(string userId)
  32. {
  33. return Ok(await _userService.GetById(userId));
  34. }
  35. [HttpPost("Create")]
  36. [ProducesResponseType(StatusCodes.Status200OK)]
  37. [Consumes("multipart/form-data")]
  38. public async Task<ActionResult<UserDto>> Create([FromForm] UserDto input)
  39. {
  40. return await _userService.Create(input);
  41. }
  42. [HttpPost("Update")]
  43. [Consumes("multipart/form-data")]
  44. [ProducesResponseType(StatusCodes.Status200OK)]
  45. public async Task Update([FromForm] UserDto input)
  46. {
  47. await _userService.Update(input);
  48. }
  49. [HttpPost("Delete")]
  50. [ProducesResponseType(StatusCodes.Status200OK)]
  51. public async Task Delete(string id)
  52. {
  53. await _userService.Delete(id);
  54. }
  55. [HttpPost("ResetPassword")]
  56. [ProducesResponseType(StatusCodes.Status200OK)]
  57. public async Task<bool> ResetPassword([FromBody] ResetPasswordDto input)
  58. {
  59. return await _userService.ResetPassword(input);
  60. }
  61. }
  62. }