开始业务模块

This commit is contained in:
橙子
2023-01-25 17:48:48 +08:00
parent 80723496d0
commit 99787950a8
60 changed files with 773 additions and 60 deletions

View File

@@ -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()
{

View File

@@ -18,6 +18,6 @@ namespace Yi.Framework.Ddd.Entities
//
// 摘要:
// Unique identifier for this entity.
TKey Id { get;}
TKey Id { get; set; }
}
}

View File

@@ -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);

View File

@@ -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);
}
}
}

View File

@@ -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);