TestService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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(ApplicationConst.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. var a = 1;
  55. var b = 0;
  56. var c = a / b;
  57. return await _testRep.GetListAsync();
  58. }
  59. /// <summary>
  60. /// 多语言测试
  61. /// </summary>
  62. /// <returns></returns>
  63. public string TestCulture()
  64. {
  65. "ddd".LogWarning();
  66. //L.SetCulture("zh-CN");
  67. //var a = L.GetSelectCulture();
  68. //var a1 = L.Text["API Interfaces"];
  69. //return $"当前语言【{a.Culture.Name}】 {a1}";
  70. L.SetCulture("en-US");
  71. var b = L.GetSelectCulture();
  72. var b1 = L.Text["API 接口"];
  73. return $"当前语言【{b.Culture.Name}】 {b1}";
  74. }
  75. /// <summary>
  76. /// 自定义规范化结果
  77. /// </summary>
  78. /// <returns></returns>
  79. [CustomUnifyResult("APP")]
  80. public string CustomUnifyResult()
  81. {
  82. return "Furion";
  83. }
  84. }