TestService.cs 1.7 KB

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