Files
mixtape/zero.Raven/Operations/RavenOperations.Delete.cs
T
2022-12-07 15:20:53 +01:00

30 lines
710 B
C#

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