更改逻辑删除问题
This commit is contained in:
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Core.Attributes;
|
||||
@@ -64,7 +65,7 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
|
||||
}
|
||||
public override async Task<bool> DeleteAsync(List<T> deleteObjs)
|
||||
{
|
||||
if (typeof(T) is ISoftDelete)
|
||||
if (typeof(ISoftDelete).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
//反射赋值
|
||||
deleteObjs.ForEach(e => ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
|
||||
@@ -77,7 +78,7 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
|
||||
}
|
||||
public override async Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
if (typeof(T) is ISoftDelete)
|
||||
if (typeof(ISoftDelete).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
var entities = await GetListAsync(whereExpression);
|
||||
//反射赋值
|
||||
@@ -91,8 +92,8 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
|
||||
}
|
||||
public override async Task<bool> DeleteByIdAsync(dynamic id)
|
||||
{
|
||||
if (typeof(T) is ISoftDelete)
|
||||
{
|
||||
if (typeof(ISoftDelete).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
var entity = await GetByIdAsync(id);
|
||||
//反射赋值
|
||||
ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, entity);
|
||||
@@ -106,9 +107,13 @@ namespace Yi.Framework.Core.Sqlsugar.Repositories
|
||||
}
|
||||
public override async Task<bool> DeleteByIdsAsync(dynamic[] ids)
|
||||
{
|
||||
if (typeof(T) is ISoftDelete)
|
||||
if (typeof(ISoftDelete).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
var entities = await _DbQueryable.In(ids).ToListAsync();
|
||||
if (entities.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//反射赋值
|
||||
entities.ForEach(e => ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
|
||||
return await UpdateRangeAsync(entities);
|
||||
|
||||
@@ -8,6 +8,6 @@ namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface IDeleteAppService<in TKey> : IApplicationService
|
||||
{
|
||||
Task DeleteAsync(TKey id);
|
||||
Task<bool> DeleteAsync(string id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -104,20 +106,40 @@ namespace Yi.Framework.Ddd.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删
|
||||
/// 单、多删
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public async Task DeleteAsync(TKey id)
|
||||
public async Task<bool> DeleteAsync(string id)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
await _repository.DeleteByIdAsync(id);
|
||||
var idsValue = id.Split(',');
|
||||
if (idsValue is null || idsValue.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
return await _repository.DeleteByIdsAsync(idsValue.Select(x => (object)x!).ToArray());
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 删
|
||||
///// </summary>
|
||||
///// <param name="id"></param>
|
||||
///// <returns></returns>
|
||||
///// <exception cref="ArgumentNullException"></exception>
|
||||
//public async Task<bool> DeleteAsync(TKey id)
|
||||
//{
|
||||
// if (id is null)
|
||||
// {
|
||||
// throw new ArgumentNullException(nameof(id));
|
||||
// }
|
||||
// return await _repository.DeleteByIdAsync(id);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 改
|
||||
/// </summary>
|
||||
@@ -131,7 +153,7 @@ namespace Yi.Framework.Ddd.Services
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
|
||||
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity.Id = id;
|
||||
await _repository.UpdateIgnoreNullAsync(entity);
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.Ddd.Services.CrudAppService`7.DeleteAsync(`3)">
|
||||
<member name="M:Yi.Framework.Ddd.Services.CrudAppService`7.DeleteAsync(System.String)">
|
||||
<summary>
|
||||
删
|
||||
单、多删
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
|
||||
Reference in New Issue
Block a user