Files
mixtape/zero.Core/Stores/StoreOperations.Delete.cs
T

26 lines
593 B
C#
Raw Normal View History

2021-11-23 22:56:22 +01:00
namespace zero.Stores;
2021-11-23 11:35:01 +01:00
2021-11-27 18:09:27 +01:00
public partial class StoreOperations : IStoreOperations
2021-11-23 11:35:01 +01:00
{
/// <inheritdoc />
2021-11-26 15:47:11 +01:00
public virtual async Task<Result<T>> Delete<T>(T model) where T : ZeroIdEntity, new()
2021-11-23 11:35:01 +01:00
{
2021-11-24 15:49:25 +01:00
if (model == null)
2021-11-23 11:35:01 +01:00
{
2021-11-26 15:47:11 +01:00
return Result<T>.Fail("@errors.ondelete.idnotfound");
2021-11-23 11:35:01 +01:00
}
2021-11-24 15:49:25 +01:00
InterceptorInstruction<T> instruction = Interceptors.ForDelete(model);
2021-11-23 11:35:01 +01:00
2021-12-28 13:23:14 +01:00
if (!await instruction.Start(this))
2021-11-24 15:49:25 +01:00
{
2021-11-23 11:35:01 +01:00
return instruction.Result;
}
2021-11-24 15:49:25 +01:00
Session.Delete(model);
2021-11-23 11:35:01 +01:00
await instruction.Complete();
await Session.SaveChangesAsync();
2021-11-26 15:47:11 +01:00
return Result<T>.Success();
2021-11-23 11:35:01 +01:00
}
}