TestService.cs 1.6 KB

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