TdevBoxTemplateController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Ropin.Inspection.Api.Common;
  5. using Ropin.Inspection.Api.Controllers;
  6. using Ropin.Inspection.Model;
  7. using Ropin.Inspection.Service;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Api
  13. {
  14. public class TdevBoxTemplateController : BaseController
  15. {
  16. public ILogger<TdevBoxTemplateController> _logger { get; }
  17. private readonly ITdevBoxTemplateService _TdevBoxTemplateService;
  18. /// <summary>
  19. /// 构造函数
  20. /// </summary>
  21. /// <param name="TdevBoxTemplateService"></param>
  22. /// <param name="logger"></param>
  23. public TdevBoxTemplateController(ITdevBoxTemplateService TdevBoxTemplateService, ILogger<TdevBoxTemplateController> logger)
  24. {
  25. _TdevBoxTemplateService = TdevBoxTemplateService;
  26. _logger = logger;
  27. }
  28. /// <summary>
  29. /// 创建盒子模板信息
  30. /// </summary>
  31. /// <param name="content"></param>
  32. /// <returns></returns>
  33. [HttpPost("CreateBoxTemplateAsync")]
  34. public async Task<ApiResult> CreateBoxTemplateAsync(TdevBoxTemplateViewModel content)
  35. {
  36. if (content == null)
  37. {
  38. return new ApiResult(ReturnCode.ArgsError);
  39. }
  40. try
  41. {
  42. await _TdevBoxTemplateService.CreateOneAsync(content);
  43. }
  44. catch (Exception ex)
  45. {
  46. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  47. }
  48. return new ApiResult(ReturnCode.Success);
  49. }
  50. /// <summary>
  51. /// 删除盒子模板信息
  52. /// </summary>
  53. /// <param name="id"></param>
  54. /// <returns></returns>
  55. [HttpDelete("DeleteBoxTemplateAsync/{id}")]
  56. public async Task<ApiResult> DeleteBoxTemplateAsync(string id)
  57. {
  58. if (string.IsNullOrEmpty(id))
  59. {
  60. return new ApiResult(ReturnCode.GeneralError);
  61. }
  62. try
  63. {
  64. await _TdevBoxTemplateService.DeleteAsync(id);
  65. }
  66. catch (Exception ex)
  67. {
  68. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  69. }
  70. return new ApiResult(ReturnCode.Success);
  71. }
  72. /// <summary>
  73. /// 更新盒子模板信息
  74. /// </summary>
  75. /// <param name="id"></param>
  76. /// <param name="updateModel"></param>
  77. /// <returns></returns>
  78. [HttpPut("UpdateBoxTemplateAsync/{id}")]
  79. [AllowAnonymous]
  80. public async Task<ApiResult> UpdateBoxTemplateAsync(string id, TdevBoxTemplateUpdateModel updateModel)
  81. {
  82. if (string.IsNullOrEmpty(id))
  83. {
  84. return new ApiResult(ReturnCode.GeneralError);
  85. }
  86. try
  87. {
  88. await _TdevBoxTemplateService.UpdateAsync(id, updateModel);
  89. }
  90. catch (Exception ex)
  91. {
  92. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  93. }
  94. return new ApiResult(ReturnCode.Success);
  95. }
  96. /// <summary>
  97. /// 通过id获取盒子模板信息
  98. /// </summary>
  99. /// <returns></returns>
  100. [HttpPost("GetBoxTemplateAsync")]
  101. [AllowAnonymous]
  102. public async Task<ApiResult> GetBoxTemplateAsync(TdevBoxTemplateSearchModel searchModel)
  103. {
  104. if (searchModel == null)
  105. {
  106. return new ApiResult(ReturnCode.ArgsError);
  107. }
  108. try
  109. {
  110. var contentList = await _TdevBoxTemplateService.GetConditionAsync(searchModel);
  111. return new ApiResult<PagesModel<TdevBoxTemplateViewModel>>(new PagesModel<TdevBoxTemplateViewModel>(contentList, searchModel));
  112. }
  113. catch (Exception ex)
  114. {
  115. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  116. }
  117. }
  118. /// <summary>
  119. ///
  120. /// </summary>
  121. /// <param name="id"></param>
  122. /// <returns></returns>
  123. //[HttpGet("GetBoxTemplateByCodeAsync/{id}")]
  124. //[AllowAnonymous]
  125. //public async Task<ApiResult> GetBoxTemplateByCodeAsync(string id)
  126. //{
  127. // if (string.IsNullOrEmpty(id))
  128. // {
  129. // return new ApiResult(ReturnCode.GeneralError);
  130. // }
  131. // try
  132. // {
  133. // var content = await _TdevBoxTemplateService.GetConditionAsync(new TdevBoxTemplateSearchModel { C_Name = id });
  134. // var dev = content.ToList();
  135. // return new ApiResult<IEnumerable<TdevBoxTemplateViewModel>>(new List<TdevBoxTemplateViewModel>(dev));
  136. // }
  137. // catch (Exception ex)
  138. // {
  139. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  140. // }
  141. //}
  142. }
  143. }