CompanyController.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public async Task<ActionResult<List<CompanyDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
  23. {
  24. return Ok( await _companyService.GetAll(pagingInput));
  25. }
  26. [HttpGet("Get")]
  27. public async Task<ActionResult<CompanyDto>> Get()
  28. {
  29. return Ok(await _companyService.GetById());
  30. }
  31. [HttpGet("GetById")]
  32. public async Task<ActionResult<CompanyDto>> GetById(long companyId)
  33. {
  34. return Ok(await _companyService.GetById(companyId));
  35. }
  36. [HttpPost("Create")]
  37. [ProducesResponseType(StatusCodes.Status200OK)]
  38. [Consumes("multipart/form-data")]
  39. [AllowAnonymous]
  40. public async Task<ActionResult<CompanyDto>> Create([FromForm] CompanyDto input)
  41. {
  42. return await _companyService.Create(input);
  43. }
  44. [HttpPost("Update")]
  45. [ProducesResponseType(StatusCodes.Status200OK)]
  46. [Consumes("multipart/form-data")]
  47. public async Task<ActionResult<CompanyDto>> Update([FromForm] CompanyDto input)
  48. {
  49. return await _companyService.Update(input);
  50. }
  51. [HttpDelete("Delete")]
  52. [ProducesResponseType(StatusCodes.Status200OK)]
  53. public async Task Delete([FromQuery] long id)
  54. {
  55. await _companyService.Delete(id);
  56. }
  57. }
  58. }