OpenAuth.Net/CodeSmith/CSharp/Web/Controller.cst

105 lines
2.8 KiB
Plaintext
Raw Normal View History

2017-11-29 18:26:36 +08:00
<%--
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="False" 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 System.Collections.Generic;
using System.Linq;
2017-11-29 18:26:36 +08:00
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
2017-11-29 18:26:36 +08:00
using OpenAuth.App;
using OpenAuth.App.Interface;
2017-12-15 00:03:06 +08:00
using OpenAuth.App.Request;
using OpenAuth.Repository.Domain;
2017-11-29 18:26:36 +08:00
namespace OpenAuth.Mvc.Controllers
{
2017-12-18 22:37:51 +08:00
public class <%=ModuleName%>sController : BaseController
2017-11-29 18:26:36 +08:00
{
private readonly <%=ModuleName%>App _app;
2017-11-29 18:26:36 +08:00
public <%=ModuleName%>sController(<%=ModuleName%>App app, IAuth auth) : base(auth)
{
_app = app;
}
//主页
2017-11-29 18:26:36 +08:00
public ActionResult Index()
{
return View();
}
/// <summary>
/// MVC界面添加
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[HttpPost]
public string Add(AddOrUpdate<%=ModuleName%>Req obj)
2017-11-29 18:26:36 +08:00
{
2017-12-15 00:03:06 +08:00
try
{
_app.Add(obj);
2017-12-15 00:03:06 +08:00
}
catch (Exception ex)
{
Result.Code = 500;
Result.Message = ex.Message;
}
return JsonHelper.Instance.Serialize(Result);
2017-11-29 18:26:36 +08:00
}
/// <summary>
/// MVC界面修改
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[HttpPost]
public string Update(AddOrUpdate<%=ModuleName%>Req obj)
2017-11-29 18:26:36 +08:00
{
try
{
_app.Update(obj);
2017-12-15 00:03:06 +08:00
2017-11-29 18:26:36 +08:00
}
catch (Exception ex)
{
2017-12-15 00:03:06 +08:00
Result.Code = 500;
Result.Message = ex.Message;
2017-11-29 18:26:36 +08:00
}
2017-12-15 00:03:06 +08:00
return JsonHelper.Instance.Serialize(Result);
2017-11-29 18:26:36 +08:00
}
/// <summary>
2017-12-18 22:37:51 +08:00
/// 加载列表
2017-11-29 18:26:36 +08:00
/// </summary>
public string Load([FromQuery]Query<%=ModuleName%>ListReq request)
2017-11-29 18:26:36 +08:00
{
return JsonHelper.Instance.Serialize(_app.Load(request));
2017-11-29 18:26:36 +08:00
}
[HttpPost]
2017-12-15 00:03:06 +08:00
public string Delete(string[] ids)
2017-11-29 18:26:36 +08:00
{
try
{
_app.Delete(ids);
2017-11-29 18:26:36 +08:00
}
catch (Exception e)
{
2017-12-15 00:03:06 +08:00
Result.Code = 500;
Result.Message = e.Message;
2017-11-29 18:26:36 +08:00
}
2017-12-15 00:03:06 +08:00
return JsonHelper.Instance.Serialize(Result);
2017-11-29 18:26:36 +08:00
}
}
2015-11-22 23:54:21 +08:00
}