CompanyController.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.Application.Services;
  8. using MTWorkHR.Application.Services.Interfaces;
  9. namespace MTWorkHR.API.Controllers
  10. {
  11. [Route("api/[controller]")]
  12. [ApiController]
  13. [AppAuthorize]
  14. public class CompanyController : ControllerBase
  15. {
  16. private readonly ICompanyService _companyService;
  17. public CompanyController(ICompanyService CompanyService)
  18. {
  19. this._companyService = CompanyService;
  20. }
  21. [HttpGet("GetAll")]
  22. [Authorize(Policy = "SuperAdminOnly")]
  23. [AppAuthorize(Permissions = "Company")]
  24. public async Task<ActionResult<List<CompanyDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
  25. {
  26. return Ok( await _companyService.GetAll(pagingInput));
  27. }
  28. [HttpGet("Get")]
  29. [AppAuthorize(Permissions = "Company")]
  30. public async Task<ActionResult<CompanyDto>> Get()
  31. {
  32. return Ok(await _companyService.GetById());
  33. }
  34. [HttpGet("GetById")]
  35. [AppAuthorize(Permissions = "Company")]
  36. public async Task<ActionResult<CompanyDto>> GetById(long companyId)
  37. {
  38. return Ok(await _companyService.GetById(companyId));
  39. }
  40. [HttpPost("Create")]
  41. [ProducesResponseType(StatusCodes.Status200OK)]
  42. [Consumes("multipart/form-data")]
  43. [AllowAnonymous]
  44. [AppAuthorize(Permissions = "Company.Create")]
  45. public async Task<ActionResult<CompanyDto>> Create([FromForm] CompanyDto input)
  46. {
  47. return await _companyService.Create(input);
  48. }
  49. [HttpPost("Update")]
  50. [ProducesResponseType(StatusCodes.Status200OK)]
  51. [Consumes("multipart/form-data")]
  52. [AppAuthorize(Permissions = "Company.Update")]
  53. public async Task<ActionResult<CompanyDto>> Update([FromForm] CompanyDto input)
  54. {
  55. return await _companyService.Update(input);
  56. }
  57. [HttpDelete("Delete")]
  58. [ProducesResponseType(StatusCodes.Status200OK)]
  59. // [AppAuthorize(Permissions = "Company.Delete")]
  60. [Authorize(Policy = "SuperAdminOnly")]
  61. [AppAuthorize(Permissions = "Company.Delete")]
  62. public async Task Delete([FromQuery] long id)
  63. {
  64. await _companyService.Delete(id);
  65. }
  66. [HttpDelete("Suspend")]
  67. [ProducesResponseType(StatusCodes.Status200OK)]
  68. //[AppAuthorize(Permissions = "Company.Suspend")]
  69. [Authorize(Policy = "SuperAdminOnly")]
  70. [AppAuthorize(Permissions = "Company.Suspend")]
  71. public async Task Suspend([FromQuery] long id)
  72. {
  73. await _companyService.Suspend(id);
  74. }
  75. }
  76. }