LargeScreenEventController.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using log4net;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Ropin.Inspection.Api.Common;
  6. using Ropin.Inspection.Model.SearchModel.LGS;
  7. using Ropin.Inspection.Model.ViewModel.LGS;
  8. using Ropin.Inspection.Model;
  9. using Ropin.Inspection.Service.LGS.Interface;
  10. using System.Threading.Tasks;
  11. using System;
  12. namespace Ropin.Inspection.Api.Controllers.LGS
  13. {
  14. public class LargeScreenEventController : BaseController
  15. {
  16. private readonly ILargeScreenEventService _repository;
  17. private static readonly ILog log = LogManager.GetLogger(typeof(LargeScreenEventController));
  18. /// <summary>
  19. /// 构造函数
  20. /// </summary>
  21. /// <param name="repository"></param>
  22. public LargeScreenEventController(ILargeScreenEventService repository)
  23. {
  24. _repository = repository;
  25. }
  26. /// <summary>
  27. /// 创建大屏控件事件
  28. /// </summary>
  29. /// <param name="content"></param>
  30. /// <returns></returns>
  31. [HttpPost("CreateLargeScreenEventAsync")]
  32. public async Task<ApiResult> CreateLargeScreenEventAsync(LargeScreenEventViewModel content)
  33. {
  34. if (content == null)
  35. {
  36. return new ApiResult(ReturnCode.ArgsError);
  37. }
  38. try
  39. {
  40. await _repository.CreateOneAsync(content);
  41. }
  42. catch (Exception ex)
  43. {
  44. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  45. }
  46. return new ApiResult(ReturnCode.Success);
  47. }
  48. /// <summary>
  49. /// 删除大屏控件事件
  50. /// </summary>
  51. /// <param name="id"></param>
  52. /// <returns></returns>
  53. [HttpDelete("DeleteLargeScreenEventAsync/{id}")]
  54. public async Task<ApiResult> DeleteLargeScreenEventAsync(string id)
  55. {
  56. if (string.IsNullOrEmpty(id))
  57. {
  58. return new ApiResult(ReturnCode.GeneralError);
  59. }
  60. try
  61. {
  62. await _repository.DeleteAsync(id);
  63. }
  64. catch (Exception ex)
  65. {
  66. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  67. }
  68. return new ApiResult(ReturnCode.Success);
  69. }
  70. /// <summary>
  71. /// 更新大屏控件事件
  72. /// </summary>
  73. /// <param name="id"></param>
  74. /// <param name="updateModel"></param>
  75. /// <returns></returns>
  76. [HttpPut("UpdateLargeScreenEventAsync/{id}")]
  77. [AllowAnonymous]
  78. public async Task<ApiResult> UpdateLargeScreenEventAsync(string id, LargeScreenEventViewModel updateModel)
  79. {
  80. if (string.IsNullOrEmpty(id))
  81. {
  82. return new ApiResult(ReturnCode.GeneralError);
  83. }
  84. try
  85. {
  86. await _repository.UpdateAsync(updateModel, id);
  87. }
  88. catch (Exception ex)
  89. {
  90. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  91. }
  92. return new ApiResult(ReturnCode.Success);
  93. }
  94. /// <summary>
  95. /// 获取大屏控件事件列表
  96. /// </summary>
  97. /// <returns></returns>
  98. [HttpPost("GetLargeScreenEventAsync")]
  99. [AllowAnonymous]
  100. public async Task<ApiResult> GetLargeScreenEventAsync(LargeScreenEventSearch searchModel)
  101. {
  102. if (searchModel == null)
  103. {
  104. return new ApiResult(ReturnCode.ArgsError);
  105. }
  106. try
  107. {
  108. var contentList = await _repository.GetConditionAsync(searchModel);
  109. return new ApiResult<PagesModel<LargeScreenEventViewModel>>(new PagesModel<LargeScreenEventViewModel>(contentList, searchModel));
  110. }
  111. catch (Exception ex)
  112. {
  113. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  114. }
  115. }
  116. /// <summary>
  117. /// 通过id获取大屏控件事件详情
  118. /// </summary>
  119. /// <returns></returns>
  120. [HttpGet("GetLargeScreenEventByIDAsync")]
  121. [AllowAnonymous]
  122. public async Task<ApiResult> GetLargeScreenEventByIDAsync(string Id)
  123. {
  124. if (string.IsNullOrEmpty(Id))
  125. {
  126. return new ApiResult(ReturnCode.ArgsError);
  127. }
  128. try
  129. {
  130. LargeScreenEventViewModel data = await _repository.GetByIdAsync(Id);
  131. return new ApiResult<LargeScreenEventViewModel>(data);
  132. }
  133. catch (Exception ex)
  134. {
  135. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  136. }
  137. }
  138. }
  139. }