AdminCarController.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Entity.WorkCar;
  4. using GxPress.Repository.Interface.WorkCar;
  5. using GxPress.Request.App.WorkCar;
  6. using Microsoft.AspNetCore.Authorization;
  7. using Microsoft.AspNetCore.Mvc;
  8. namespace GxPress.Api.AdminControllers
  9. {
  10. /// <summary>
  11. /// 会议
  12. /// </summary>
  13. [Route("api/admin/car")]
  14. [ApiController]
  15. [Authorize]
  16. public class AdminCarController : ControllerBase
  17. {
  18. private readonly ICarTypeRepository _carTypeRepository;
  19. private readonly ICarOrderRepository _carOrderRepository;
  20. private readonly ICarRepository _carRepository;
  21. public AdminCarController(ICarTypeRepository carTypeRepository, ICarOrderRepository carOrderRepository, ICarRepository carRepository)
  22. {
  23. _carTypeRepository = carTypeRepository;
  24. _carOrderRepository = carOrderRepository;
  25. _carRepository = carRepository;
  26. }
  27. /// <summary>
  28. /// 新增车辆类型
  29. /// </summary>
  30. /// <param name="request"></param>
  31. /// <returns></returns>
  32. [HttpPost("type")]
  33. public async Task<CarType> TypeAdd([FromBody] CarType request)
  34. {
  35. request.Id = await _carTypeRepository.InsertAsync(request);
  36. return request;
  37. }
  38. /// <summary>
  39. /// 修改车辆类型
  40. /// </summary>
  41. /// <param name="request"></param>
  42. /// <returns></returns>
  43. [HttpPut("type")]
  44. public async Task TypeEdit([FromBody] CarType request)
  45. {
  46. await _carTypeRepository.UpdateAsync(request);
  47. }
  48. /// <summary>
  49. /// 获取车辆类型列表
  50. /// </summary>
  51. /// <returns></returns>
  52. [HttpGet("type")]
  53. public async Task<IEnumerable<CarType>> TypeList()
  54. {
  55. return await _carTypeRepository.GetListAsync();
  56. }
  57. /// <summary>
  58. /// 删除车辆类型
  59. /// </summary>
  60. /// <returns></returns>
  61. [HttpDelete("type/{id}")]
  62. public async Task<bool> TypeRemove([FromRoute]int id)
  63. {
  64. return await _carTypeRepository.DeleteAsync(id);
  65. }
  66. /// <summary>
  67. /// 新增车辆
  68. /// </summary>
  69. /// <param name="request"></param>
  70. /// <returns></returns>
  71. [HttpPost("")]
  72. public async Task<Car> CarAdd([FromBody] Car request)
  73. {
  74. request.Id = await _carRepository.InsertAsync(request);
  75. return request;
  76. }
  77. /// <summary>
  78. /// 修改车辆
  79. /// </summary>
  80. /// <param name="request"></param>
  81. /// <returns></returns>
  82. [HttpPut("")]
  83. public async Task CarEdit([FromBody] Car request)
  84. {
  85. await _carRepository.UpdateAsync(request);
  86. }
  87. /// <summary>
  88. /// 获取车辆列表
  89. /// </summary>
  90. /// <returns></returns>
  91. [HttpGet("")]
  92. public async Task<IEnumerable<Car>> CarList([FromQuery] CarRequest request)
  93. {
  94. return await _carRepository.GetListAsync(request.TypeId);
  95. }
  96. /// <summary>
  97. /// 删除车辆
  98. /// </summary>
  99. /// <returns></returns>
  100. [HttpDelete("{id}")]
  101. public async Task<bool> CarRemove([FromRoute]int id)
  102. {
  103. return await _carRepository.DeleteAsync(id);
  104. }
  105. }
  106. }