UserController.cs 2.5 KB

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