TestService.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Admin.NET.Application.Const;
  2. using Furion.DatabaseAccessor;
  3. using Microsoft.AspNetCore.Authorization;
  4. namespace Admin.NET.Application.Serice;
  5. /// <summary>
  6. /// 自己业务服务
  7. /// </summary>
  8. [ApiDescriptionSettings(TestConst.GroupName, Name = "XXX模块", Order = 200)]
  9. [AllowAnonymous]
  10. public class TestService : IDynamicApiController, ITransient
  11. {
  12. private readonly SqlSugarRepository<Test> _testRep;
  13. public TestService(SqlSugarRepository<Test> testRep)
  14. {
  15. _testRep = testRep;
  16. }
  17. /// <summary>
  18. /// 获取列表
  19. /// </summary>
  20. /// <returns></returns>
  21. [HttpGet("/test/list")]
  22. public async Task<List<Test>> GetTestList()
  23. {
  24. return await _testRep.GetListAsync();
  25. }
  26. /// <summary>
  27. /// 事务和工作单元测试
  28. /// </summary>
  29. /// <returns></returns>
  30. [HttpGet("/test/list2")]
  31. [UnitOfWork]
  32. public async Task<List<Test>> TestUnitOfWork()
  33. {
  34. await _testRep.InsertAsync(new Test() { Name = "admin" });
  35. throw new Exception("异常");
  36. return await _testRep.GetListAsync();
  37. }
  38. }