.
This commit is contained in:
35
Web/public/doc-code/application/dto.cs
Normal file
35
Web/public/doc-code/application/dto.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
// 继承PageInputBase,可以直接使用一些通用的查询和分页字段
|
||||
public class DtoPageInput : Core.PageInputBase {}
|
||||
|
||||
// 可定义一个主键Dto
|
||||
public class DtoKeyInput
|
||||
{
|
||||
public virtual string Id { get; set; }
|
||||
}
|
||||
|
||||
// 可定义一个必传主键的Dto
|
||||
public class DtoKeyRequiredInput : DtoKeyInput
|
||||
{
|
||||
[Required]
|
||||
public override string Id { get; set; }
|
||||
}
|
||||
|
||||
public class DtoAddInput
|
||||
{
|
||||
[MaxLength(100)]
|
||||
[Required]
|
||||
public string RequiredString { get; set; }
|
||||
}
|
||||
|
||||
public class DtoUpdateInput : DtoAddInput
|
||||
{
|
||||
[Required]
|
||||
public override string Id { get; set; }
|
||||
}
|
||||
|
||||
public class DtoDeleteInput: DtoKeyInput {}
|
||||
}
|
||||
26
Web/public/doc-code/application/entity.cs
Normal file
26
Web/public/doc-code/application/entity.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
// Table特性设定表在数据库中的表名
|
||||
[Table("bs_table_name")]
|
||||
[Comment("表名")]
|
||||
// 这里继承Core.DEntityBase,会自动添加Id及一些常用字段
|
||||
public class BsTableName : Core.DEntityBase
|
||||
{
|
||||
// Comment特性用于生成字段说明
|
||||
[Comment("字符字段")]
|
||||
// MaxLength特性用于限定字段值长度,可以不设置
|
||||
[MaxLength(50)]
|
||||
// Required特性设置字段是否不为空
|
||||
[Required]
|
||||
public string StringField { get; set; }
|
||||
|
||||
[Comment("整形字段")]
|
||||
[MaxLength(3)]
|
||||
[Required]
|
||||
public int IntField { get; set; }
|
||||
}
|
||||
}
|
||||
15
Web/public/doc-code/application/interface.cs
Normal file
15
Web/public/doc-code/application/interface.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface Interface
|
||||
{
|
||||
Task<dynamic> Page(DtoPageInput input);
|
||||
|
||||
Task Add(DtoAddInput input);
|
||||
|
||||
Task Update(DtoUpdateInput input);
|
||||
|
||||
Task Delete(DtoDeleteInput input);
|
||||
}
|
||||
}
|
||||
90
Web/public/doc-code/application/service.cs
Normal file
90
Web/public/doc-code/application/service.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
[ApiDescriptionSettings(Name = "ServiceDoc")]
|
||||
public class Service : Interface, IDynamicApiController, ITransient
|
||||
{
|
||||
// Dapper仓储
|
||||
private readonly IDapperRepository _dapperRep;
|
||||
|
||||
// 用户信息
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
// 数据(实体Entity)仓储
|
||||
private readonly IRepository<Entity> _entityRep;
|
||||
|
||||
public Service(
|
||||
IDapperRepository dapperRep,
|
||||
|
||||
IUserManager userManager,
|
||||
|
||||
IRepository<Entity> entityRep
|
||||
)
|
||||
{
|
||||
_dapperRep = dapperRep;
|
||||
|
||||
_userManager = userManager;
|
||||
|
||||
_entityRep = entityRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询 - EF方式
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<dynamic> Page(DtoPageInput input)
|
||||
{
|
||||
var data = await _entityRep.DetachedEntities.ToPageData(input);
|
||||
return PageDataResult<Entity>.PageResult(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询 - Dapper方式
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<dynamic> Page(DtoPageInput input)
|
||||
{
|
||||
var sql = "...";
|
||||
var data = await _dapperRep.QueryPageDataDynamic(sql, input);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Add(DtoAddInput input)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Update(DtoUpdateInput input)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Delete(DtoDeleteInput input)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user