From 360182b297f6e127b251588265177a3581d561f8 Mon Sep 17 00:00:00 2001 From: wintel Date: Sun, 23 Jun 2024 20:57:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4WebApi=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeSmith/CSharp/ApiGenerate.cst | 22 ---- CodeSmith/CSharp/ApiGenerate/Controller.cst | 128 -------------------- 2 files changed, 150 deletions(-) delete mode 100644 CodeSmith/CSharp/ApiGenerate/Controller.cst diff --git a/CodeSmith/CSharp/ApiGenerate.cst b/CodeSmith/CSharp/ApiGenerate.cst index cc7834ef..58b23eeb 100644 --- a/CodeSmith/CSharp/ApiGenerate.cst +++ b/CodeSmith/CSharp/ApiGenerate.cst @@ -83,9 +83,6 @@ Category="1.Database" Description="可以选择一个或多个表(使用Ctrl <%@ Register Name="ModifyReqGenerateClass" Template="ApiGenerate\ModifyReq.cst" MergeProperties="False" %> -<%@ Register Name="ControllerGenerateClass" - Template="ApiGenerate\Controller.cst" - MergeProperties="False" %> 开始创建OpenAuth.Core WebApi相关代码 ... <% Generate(); %> @@ -105,7 +102,6 @@ Category="1.Database" Description="可以选择一个或多个表(使用Ctrl } CreateEntityClasses(); - CreateControllerClass(); CreateApplicationClass(); CreateReqClass(); CreateContextClass(); @@ -154,24 +150,6 @@ Category="1.Database" Description="可以选择一个或多个表(使用Ctrl } - //创建控制器,如UserManagerController.cs - public void CreateControllerClass() - { - ControllerGenerateClass generatedClass = this.Create(); - this.CopyPropertiesTo(generatedClass); - - - foreach(TableSchema table in tables) - { - string generatedFile = Path.GetFullPath(directory) + "OpenAuth.WebApi\\Controllers\\"+ table.Name + "sController.cs"; - - generatedClass.ModuleName = table.Name; - - Response.WriteLine("已生成"+generatedFile); - generatedClass.RenderToFile(generatedFile, generatedFile, true); - } - } - //创建APP层,如UserManagerApp.cs public void CreateApplicationClass() { diff --git a/CodeSmith/CSharp/ApiGenerate/Controller.cst b/CodeSmith/CSharp/ApiGenerate/Controller.cst deleted file mode 100644 index 30119a0e..00000000 --- a/CodeSmith/CSharp/ApiGenerate/Controller.cst +++ /dev/null @@ -1,128 +0,0 @@ -<%-- -Name: Database Table Properties -Author: yubaolee -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="控制器" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - -using System; -using Infrastructure; -using Microsoft.AspNetCore.Mvc; -using OpenAuth.App; -using OpenAuth.App.Request; -using OpenAuth.App.Response; -using OpenAuth.Repository.Domain; - -namespace OpenAuth.WebApi.Controllers -{ - /// - /// <%=ModuleName%>操作 - /// - [Route("api/[controller]/[action]")] - [ApiController] - public class <%=ModuleName%>sController : ControllerBase - { - private readonly <%=ModuleName%>App _app; - - /// - /// //获取详情 - /// - [HttpGet] - public Response<<%=ModuleName%>> Get(string id) - { - var result = new Response<<%=ModuleName%>>(); - try - { - result.Result = _app.Get(id); - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - - /// - /// 添加 - /// - [HttpPost] - public Response Add(AddOrUpdate<%=ModuleName%>Req obj) - { - var result = new Response(); - try - { - _app.Add(obj); - - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - - /// - /// 修改 - /// - [HttpPost] - public Response Update(AddOrUpdate<%=ModuleName%>Req obj) - { - var result = new Response(); - try - { - _app.Update(obj); - - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - - /// - /// 加载列表 - /// - [HttpGet] - public TableData Load([FromQuery]Query<%=ModuleName%>ListReq request) - { - return _app.Load(request); - } - - /// - /// 批量删除 - /// - [HttpPost] - public Response Delete([FromBody]string[] ids) - { - var result = new Response(); - try - { - _app.Delete(ids); - - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - - public <%=ModuleName%>sController(<%=ModuleName%>App app) - { - _app = app; - } - } -}