TestService.cs 5.5 KB

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