TsysPrivController.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using Autofac.Core;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.Extensions.Logging;
  6. using Ropin.Inspection.Api.Common;
  7. using Ropin.Inspection.Model.ViewModel;
  8. using Ropin.Inspection.Service;
  9. using Ropin.Inspection.Service.SYS.Interface;
  10. using System.Collections.Generic;
  11. using System.Threading.Tasks;
  12. using System;
  13. using Ropin.Inspection.Model.ViewModel.SYS;
  14. namespace Ropin.Inspection.Api.Controllers.SYS
  15. {
  16. [AllowAnonymous]
  17. public class TsysPrivController : BaseController
  18. {
  19. public ILogger<TsysPrivController> _logger { get; }
  20. private readonly ITsysPrivService _service;
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="service"></param>
  25. /// <param name="logger"></param>
  26. public TsysPrivController(ITsysPrivService service, ILogger<TsysPrivController> logger)
  27. {
  28. _service = service;
  29. _logger = logger;
  30. }
  31. /// <summary>
  32. /// 获取树型列表
  33. /// </summary>
  34. /// <returns></returns>
  35. [HttpPost("GetPrivTree")]
  36. public async Task<ApiResult> GetListTreeAsync(TsysPrivSearch model)
  37. {
  38. try
  39. {
  40. if (model==null)
  41. {
  42. model = new TsysPrivSearch();
  43. }
  44. var list = await _service.GetPrivTree(model);
  45. return new ApiResult<List<TsysPrivTreeModel>>(list);
  46. }
  47. catch (Exception ex)
  48. {
  49. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  50. }
  51. }
  52. /// <summary>
  53. /// 创建
  54. /// </summary>
  55. /// <param name="entity"></param>
  56. /// <returns></returns>
  57. [Route("CreatePrivAsync")]
  58. [HttpPost]
  59. public async Task<ApiResult> CreatePrivAsync(TsysPrivViewModel entity)
  60. {
  61. if (entity == null)
  62. {
  63. return new ApiResult(ReturnCode.ArgsError);
  64. }
  65. try
  66. {
  67. await _service.CreateOneAsync(entity);
  68. }
  69. catch (Exception ex)
  70. {
  71. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  72. }
  73. return new ApiResult(ReturnCode.Success);
  74. }
  75. /// <summary>
  76. /// 更新
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <param name="updateModel"></param>
  80. /// <returns></returns>
  81. [HttpPut("UpdatePriv/{id}")]
  82. public async Task<ApiResult> UpdatePrivAsync(string id, TsysPrivViewModel updateModel)
  83. {
  84. if (string.IsNullOrEmpty(id))
  85. {
  86. return new ApiResult(ReturnCode.GeneralError);
  87. }
  88. try
  89. {
  90. await _service.UpdateOneAsync(id, updateModel);
  91. }
  92. catch (Exception ex)
  93. {
  94. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  95. }
  96. return new ApiResult(ReturnCode.Success);
  97. }
  98. /// <summary>
  99. /// 删除
  100. /// </summary>
  101. /// <param name="id"></param>
  102. /// <returns></returns>
  103. [HttpDelete("DeletePriv/{id}")]
  104. public async Task<ApiResult> DeletePriv(string id)
  105. {
  106. if (string.IsNullOrEmpty(id))
  107. {
  108. return new ApiResult(ReturnCode.GeneralError);
  109. }
  110. try
  111. {
  112. await _service.DeleteAsync(id);
  113. }
  114. catch (Exception ex)
  115. {
  116. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  117. }
  118. return new ApiResult(ReturnCode.Success);
  119. }
  120. }
  121. }