mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-11 20:19:27 +08:00
开始业务模块
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Yi.Framework.Ddd.Entities
|
||||
[Serializable]
|
||||
public abstract class Entity<TKey> : Entity, IEntity<TKey>, IEntity
|
||||
{
|
||||
public virtual TKey Id { get; protected set; }
|
||||
public virtual TKey Id { get; set; }
|
||||
|
||||
protected Entity()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,6 @@ namespace Yi.Framework.Ddd.Entities
|
||||
//
|
||||
// 摘要:
|
||||
// Unique identifier for this entity.
|
||||
TKey Id { get;}
|
||||
TKey Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace Yi.Framework.Ddd.Repositories
|
||||
Task<bool> UpdateAsync(T updateObj);
|
||||
Task<bool> UpdateRangeAsync(List<T> updateObjs);
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> UpdateIgnoreNullAsync(T updateObj);
|
||||
|
||||
//删除
|
||||
Task<bool> DeleteAsync(T deleteObj);
|
||||
|
||||
@@ -82,6 +82,12 @@ namespace Yi.Framework.Ddd.Services
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected virtual Task<TEntity> MapToEntityAsync(TUpdateInput updateInput)
|
||||
{
|
||||
var entity = _mapper.Map<TEntity>(updateInput);
|
||||
return Task.FromResult(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// </summary>
|
||||
@@ -125,12 +131,14 @@ namespace Yi.Framework.Ddd.Services
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
var entity = await _repository.GetByIdAsync(id);
|
||||
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity.Id = id;
|
||||
await _repository.UpdateIgnoreNullAsync(entity);
|
||||
|
||||
await MapToEntityAsync(input, entity);
|
||||
await _repository.UpdateAsync(entity);
|
||||
var newEntity = await _repository.GetByIdAsync(id);
|
||||
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
return await MapToGetOutputDtoAsync(newEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ where TEntityDto : IEntityDto<TKey>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public async Task<TGetOutputDto> GetAsync(TKey id)
|
||||
public virtual async Task<TGetOutputDto> GetAsync(TKey id)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ where TEntityDto : IEntityDto<TKey>
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||
public virtual async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||
{
|
||||
|
||||
var totalCount = await _repository.CountAsync(_ => true);
|
||||
|
||||
Reference in New Issue
Block a user