WebApi开发框架接口模版代码
基础资料管理 - WebApi接口C#模版代码
控制器层(Controller)
C# 全选
/// <summary>
/// 货币基础资料控制器
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
public class dt_CurrencyController : _BaseSignController
{
Idt_CurrencyBusiness _business;
public dt_CurrencyController(Idt_CurrencyBusiness business)
{
_business = business;
}
#region 基础资料5个标准接口
[HttpPost]
public async Task<dt_Currency> GetDataByKey(QueryKey input)
{
return await _business.GetDataByKey(input);
}
[HttpPost]
public async Task<bool> Delete(QueryKey input)
{
return await _business.Delete(input);
}
[HttpPost]
public async Task<List<dt_Currency>> GetSummaryData()
{
return await _business.GetSummaryData();
}
[HttpPost]
public async Task<List<dt_Currency>> GetLookupData()
{
return await _business.GetLookupData();
}
[HttpPost]
public async Task<bool> Update(MasterDataUpdate<dt_Currency> data)
{
return await _business.Update(data);
}
#endregion
#region 其他扩展接口
/// <summary>
/// 如果编码手工录入且前端检查是否重复,需要调用CheckNoExists接口
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<bool> CheckNoExists(QueryKey input)
{
return await _business.CheckNoExists(input);
}
/// <summary>
/// 如果界面支持查询功能,需要调用Query接口
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<List<dt_Currency>> Query(req_Currency input)
{
return await _business.Query(input);
}
/// <summary>
/// 如果编码自动生成,需要调用UpdateEx接口
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
[HttpPost]
public async Task<SaveResult> UpdateEx(MasterDataUpdate<dt_Currency> data)
{
return await _business.UpdateEx(data);
}
#endregion
}
IBusiness业务层接口
C# 全选
public interface Idt_CurrencyBusiness
{
Task<dt_Currency> GetDataByKey(QueryKey input);
Task<bool> Delete(QueryKey input);
Task<List<dt_Currency>> GetSummaryData();
Task<List<dt_Currency>> GetLookupData();
Task<bool> Update(MasterDataUpdate<dt_Currency> input);
Task<bool> CheckNoExists(QueryKey input);
Task<List<dt_Currency>> Query(req_Currency input);
Task<SaveResult> UpdateEx(MasterDataUpdate<dt_Currency> data);
}
Business业务层
C# 全选
public class dt_CurrencyBusiness : _BaseBusiness<dt_Currency>, Idt_CurrencyBusiness, ITransientDependency
{
//注意:支持多种连接策略下,DAL层作为Client端与WebApi端的共用模块
private dal_Currency _DAL;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="user">当前用户上下文</param>
/// <param name="db">当前主数据所在的数据库实例</param>
public dt_CurrencyBusiness(IUserContext user, INormalDbAccessor db) : base(user, db)
{
_DAL = new dal_Currency(_Loginer);
}
/// <summary>
/// 查询
/// </summary>
/// <param name="input">查询条件</param>
/// <returns></returns>
public async Task<List<dt_Currency>> Query(req_Currency input)
{
return await Task.FromResult(_DAL.Query(input));
}
/// <summary>
/// 删除
/// </summary>
/// <param name="input">主键</param>
/// <returns></returns>
public async Task<bool> Delete(QueryKey input)
{
return await Task.FromResult(_DAL.Delete(input.Key));
}
/// <summary>
/// 根据主键获取一条主数据
/// </summary>
/// <param name="input">主键</param>
/// <returns></returns>
public async Task<dt_Currency> GetDataByKey(QueryKey input)
{
return await Task.FromResult(_DAL.GetDataByKey(input.Key));
}
/// <summary>
/// 提交主数据,保存资料
/// </summary>
/// <param name="input">前端资料</param>
/// <returns></returns>
public async Task<bool> Update(MasterDataUpdate<dt_Currency> input)
{
return await Task.FromResult(_DAL.Update(input));
}
public async Task<SaveResult> UpdateEx(MasterDataUpdate<dt_Currency> input)
{
return await Task.FromResult(_DAL.UpdateEx(input));
}
/// <summary>
/// 获取表格默认显示的数据
/// </summary>
/// <returns></returns>
public async Task<List<dt_Currency>> GetSummaryData()
{
return await Task.FromResult(_DAL.GetSummaryData());
}
/// <summary>
/// 获取该主数据作为Lookup数据源的数据。
/// </summary>
/// <returns></returns>
public async Task<List<dt_Currency>> GetLookupData()
{
return await Task.FromResult(_DAL.GetLookupData());
}
/// <summary>
/// 检查指定字段的值是否重复,如:客户编码、商品编码
/// </summary>
/// <param name="input">字段的值</param>
/// <returns></returns>
public async Task<bool> CheckNoExists(QueryKey input)
{
return await Task.FromResult(_DAL.CheckNoExists(input.Key));
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
WebApi-NETCore-V3 C/S框架网