Files
mixtape/zero.Core/Stores/StoreOperations.Delete.cs
T
2021-11-24 15:49:25 +01:00

26 lines
597 B
C#

namespace zero.Stores;
public abstract partial class StoreOperations
{
/// <inheritdoc />
public virtual async Task<EntityResult<T>> Delete<T>(T model) where T : ZeroIdEntity, new()
{
if (model == null)
{
return EntityResult<T>.Fail("@errors.ondelete.idnotfound");
}
InterceptorInstruction<T> instruction = Interceptors.ForDelete(model);
if (!await instruction.Start())
{
return instruction.Result;
}
Session.Delete(model);
await instruction.Complete();
await Session.SaveChangesAsync();
return EntityResult<T>.Success();
}
}