TestService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. /// <summary>
  64. /// 测试 Markdown
  65. /// </summary>
  66. /// <remarks>
  67. /// # 先知 / Furion ([探索版](https://gitee.com/dotnetchina/Furion/tree/experimental/))
  68. ///
  69. /// 一个应用程序框架,您可以将它集成到任何.NET/C# 应用程序中。
  70. ///
  71. /// An application framework that you can integrate into any.NET/C# application.
  72. ///
  73. /// ## 安装 / Installation
  74. ///
  75. /// - [Package Manager] (https://www.nuget.org/packages/Furion)
  76. ///
  77. /// ```powershell
  78. /// Install-Package Furion
  79. /// ```
  80. ///
  81. /// - [.NET CLI] (https://www.nuget.org/packages/Furion)
  82. ///
  83. /// ```powershell
  84. /// dotnet add package Furion
  85. /// ```
  86. ///
  87. /// ## 例子 / Examples
  88. ///
  89. /// 我们在[主页](https://dotnetchina.gitee.io/furion)上有不少例子,这是让您入门的第一个:
  90. ///
  91. /// We have several examples [on the website] (https://dotnetchina.gitee.io/furion). Here is the first one to get you started:
  92. ///
  93. /// ```cs
  94. /// Serve.Run();
  95. ///
  96. /// [DynamicApiController]
  97. /// public class HelloService
  98. /// {
  99. /// public string Say()
  100. /// {
  101. /// return "Hello, Furion";
  102. /// }
  103. /// }
  104. /// ```
  105. ///
  106. /// 打开浏览器访问 `https://localhost:5001`。
  107. ///
  108. /// Open browser access `https://localhost:5001`.
  109. ///
  110. /// ## 文档 / Documentation
  111. ///
  112. /// 您可以在[主页] (https://dotnetchina.gitee.io/furion)或[备份主页](https://furion.icu)找到 Furion 文档。
  113. ///
  114. /// You can find the Furion documentation[on the website](https://dotnetchina.gitee.io/furion) or [on the backup website](https://furion.icu).
  115. ///
  116. /// ## 贡献 / Contributing
  117. ///
  118. /// 该存储库的主要目的是继续发展 Furion 核心,使其更快、更易于使用。 Furion 的开发在[Gitee](https://gitee.com/dotnetchina/Furion) 上公开进行,我们感谢社区贡献错误修复和改进。
  119. ///
  120. /// 阅读[贡献指南] (https://dotnetchina.gitee.io/furion/docs/contribute)内容,了解如何参与改进 Furion。
  121. ///
  122. /// The main purpose of this repository is to continue evolving Furion core, making it faster and easier to use.Development of Furion happens in the open on[Gitee] (https://gitee.com/dotnetchina/Furion), and we are grateful to the community for contributing bugfixes and improvements.
  123. ///
  124. /// Read[contribution documents] (https://dotnetchina.gitee.io/furion/docs/contribute) to learn how you can take part in improving Furion.
  125. ///
  126. /// ## 许可证 / License
  127. ///
  128. /// Furion 采用[MulanPSL - 2.0](https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) 开源许可证。
  129. ///
  130. /// Furion uses the[MulanPSL - 2.0] (https://gitee.com/dotnetchina/Furion/blob/master/LICENSE) open source license.
  131. ///
  132. /// ```
  133. /// Copyright(c) 2020-2022 百小僧, Baiqian Co., Ltd.
  134. /// Furion is licensed under Mulan PSL v2.
  135. /// You can use this software according to the terms andconditions of the Mulan PSL v2.
  136. /// You may obtain a copy of Mulan PSL v2 at:
  137. /// https://gitee.com/dotnetchina/Furion/blob/master/LICENSE
  138. /// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUTWARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  139. /// See the Mulan PSL v2 for more details.
  140. /// ```
  141. ///
  142. /// </remarks>
  143. /// <returns></returns>
  144. public string GetDescription()
  145. {
  146. return "Furion";
  147. }
  148. }