Files
mixtape/zero.Raven/Operations/RavenOperations.Delete.cs
T
2022-12-13 16:25:36 +01:00

37 lines
886 B
C#

namespace zero.Raven;
public partial class RavenOperations : IRavenOperations
{
/// <inheritdoc />
public virtual Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new()
=> Delete<T>(model.Id);
/// <inheritdoc />
public virtual async Task<Result<T>> Delete<T>(string id) where T : ZeroIdEntity, new()
{
T model = await Load<T>(id);
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<T>(model);
await Session.SaveChangesAsync();
if (InterceptorBlocker == null)
{
await instruction.Complete();
}
await Session.SaveChangesAsync();
return Result<T>.Success();
}
}