Files
mixtape/zero.Core/Stores/StoreOperations.Delete.cs
T
2021-12-28 13:23:14 +01:00

26 lines
593 B
C#

namespace zero.Stores;
public partial class StoreOperations : IStoreOperations
{
/// <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 (!await instruction.Start(this))
{
return instruction.Result;
}
Session.Delete(model);
await instruction.Complete();
await Session.SaveChangesAsync();
return Result<T>.Success();
}
}