base优化 新增根据表达式,删除实体

master
xiaochanghai 1 year ago
parent ea4b656992
commit f52ee0da99
  1. 1
      Tiobon.Core.Api/Controllers/Base/BaseController.cs
  2. 4
      Tiobon.Core.Api/Controllers/Ghre/Ghre_QuestionController.cs
  3. 7
      Tiobon.Core.IServices/BASE/IBaseServices.cs
  4. 9
      Tiobon.Core.Repository/BASE/BaseRepository.cs
  5. 7
      Tiobon.Core.Repository/BASE/IBaseRepository.cs
  6. 15
      Tiobon.Core.Services/BASE/BaseServices.cs

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.InteropServices.Marshalling;
namespace Tiobon.Core.Controllers;

@ -90,9 +90,7 @@ public class Ghre_QuestionController : BaseController<IGhre_QuestionServices, Gh
[HttpPut("{Id}")]
public override async Task<ServiceResult> Put(long Id, [FromBody] EditGhre_QuestionInput editModel)
{
var answers1 = await _ghre_QuestionAnswerServices.Query(d => d.QuestionId == Id);
var answerIds = answers1.Select(x => x.Id).ToList();
await _ghre_QuestionAnswerServices.DeleteByIds1(answerIds.ToArray());
await _ghre_QuestionAnswerServices.Delete(x=>x.QuestionId == Id);
var answers = editModel.Answers;
if (answers.Any())
{

@ -103,6 +103,13 @@ namespace Tiobon.Core.IServices.BASE
Task<bool> DeleteByIds(object[] ids);
Task<bool> DeleteByIds1(long[] ids);
/// <summary>
/// 根据表达式,删除实体
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression);
Task<bool> Update(long Id, TEditDto model);
Task<bool> Update(Dictionary<long, TEditDto> editModels);
Task<bool> Update(List<TEntity> model);

@ -252,6 +252,15 @@ namespace Tiobon.Core.Repository.Base
return await _db.Deleteable<TEntity>().In(ids).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 根据表达式,删除实体
/// </summary>
/// <param name="id">主键ID</param>
/// <returns></returns>
public async Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression)
{
return await _db.Deleteable<TEntity>().Where(whereExpression).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 查询所有数据

@ -76,6 +76,13 @@ namespace Tiobon.Core.IRepository.Base
/// <returns></returns>
Task<bool> DeleteByIds(object[] ids);
/// <summary>
/// 根据表达式,删除实体
/// </summary>
/// <param name="whereExpression"></param>
/// <returns></returns>
Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression);
/// <summary>
/// 更新model
/// </summary>

@ -403,6 +403,8 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
return Mapper.Map(data).ToANew<List<TEntityDto>>();
}
#region 新增
/// <summary>
/// 写入实体数据
/// </summary>
@ -452,6 +454,7 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
});
return await BaseDal.Add(list);
}
#endregion
/// <summary>
/// 更新实体数据
@ -611,6 +614,15 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
return await BaseDal.Update(entities);
}
/// <summary>
/// 根据表达式,删除实体
/// </summary>
/// <param name="whereExpression">表达式</param>
/// <returns></returns>
public async Task<bool> Delete(Expression<Func<TEntity, bool>> whereExpression)
{
return await BaseDal.Delete(whereExpression);
}
/// <summary>
/// 查询所有数据
@ -891,7 +903,7 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
};
}
#region 检查表中是否已经存在相同代码的数据
public static void CheckOnly(TEntity entity, long? id = null)
{
@ -986,6 +998,7 @@ public class BaseServices<TEntity, TEntityDto, TInsertDto, TEditDto> : IBaseServ
throw;
}
}
#endregion
#endregion
}
Loading…
Cancel
Save