TestService.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using Admin.NET.Application.Const;
  2. using AngleSharp;
  3. using AngleSharp.Html.Dom;
  4. using Furion.DatabaseAccessor;
  5. using Furion.FriendlyException;
  6. using Furion.Localization;
  7. using Furion.Logging.Extensions;
  8. using Microsoft.AspNetCore.Authorization;
  9. namespace Admin.NET.Application.Service;
  10. /// <summary>
  11. /// 自己业务服务
  12. /// </summary>
  13. [ApiDescriptionSettings(ApplicationConst.GroupName, Order = 200)]
  14. [AllowAnonymous]
  15. public class TestService : IDynamicApiController, ITransient
  16. {
  17. private readonly SqlSugarRepository<Test> _testRep;
  18. public TestService(SqlSugarRepository<Test> testRep)
  19. {
  20. _testRep = testRep;
  21. }
  22. /// <summary>
  23. /// 测试
  24. /// </summary>
  25. public string GetName()
  26. {
  27. return "Furion";
  28. }
  29. /// <summary>
  30. /// 获取列表
  31. /// </summary>
  32. /// <returns></returns>
  33. [HttpGet("/test/list")]
  34. public async Task<List<Test>> GetTestList()
  35. {
  36. return await _testRep.GetListAsync();
  37. }
  38. /// <summary>
  39. /// 异常测试
  40. /// </summary>
  41. /// <returns></returns>
  42. public void TestException()
  43. {
  44. throw new Exception("异常");
  45. throw Oops.Oh("异常").WithData("数据");
  46. }
  47. /// <summary>
  48. /// 事务和工作单元测试
  49. /// </summary>
  50. /// <returns></returns>
  51. [HttpGet("/test/list2")]
  52. [UnitOfWork]
  53. public async Task<List<Test>> TestUnitOfWork()
  54. {
  55. await _testRep.InsertAsync(new Test() { Name = "admin" });
  56. var a = 1;
  57. var b = 0;
  58. var c = a / b;
  59. return await _testRep.GetListAsync();
  60. }
  61. /// <summary>
  62. /// 多语言测试
  63. /// </summary>
  64. /// <returns></returns>
  65. public string TestCulture()
  66. {
  67. "ddd".LogWarning();
  68. //L.SetCulture("zh-CN");
  69. //var a = L.GetSelectCulture();
  70. //var a1 = L.Text["API Interfaces"];
  71. //return $"当前语言【{a.Culture.Name}】 {a1}";
  72. L.SetCulture("en-US");
  73. var b = L.GetSelectCulture();
  74. var b1 = L.Text["API 接口"];
  75. return $"当前语言【{b.Culture.Name}】 {b1}";
  76. }
  77. /// <summary>
  78. /// 自定义规范化结果
  79. /// </summary>
  80. /// <returns></returns>
  81. [CustomUnifyResult("APP")]
  82. public string CustomUnifyResult()
  83. {
  84. return "Furion";
  85. }
  86. }