namespace zero.Core; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using zero.Core.Entities; using zero.Core.Extensions; public abstract partial class EntityCollection { /// public virtual async Task> Delete(string id) { if (id.IsNullOrEmpty()) { return EntityResult.Fail("@errors.ondelete.idnotfound"); } T entity = await Session.LoadAsync(id); if (entity == null) { return EntityResult.Fail("@errors.ondelete.idnotfound"); } InterceptorInstruction instruction = Interceptors.CreateInstruction(this, InterceptorType.Delete, entity); if (!await instruction.Run()) { return instruction.Result; } Session.Delete(entity); await instruction.Complete(); await Session.SaveChangesAsync(); return EntityResult.Success(); } /// public virtual async Task> Delete(T model) => await Delete(model?.Id); /// public virtual async Task Delete(IEnumerable models) => await Delete(models.Select(x => x.Id)); /// public virtual async Task Delete(IEnumerable ids) { int successCount = 0; foreach (string id in ids) { EntityResult result = await Delete(id); successCount += result.IsSuccess ? 1 : 0; } return successCount; } }