TestService.cs 2.2 KB

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