Files
mixtape/zero.Core/Architecture/Blueprints/BlueprintChildInterceptor.cs
T

32 lines
989 B
C#
Raw Normal View History

2021-11-22 14:29:22 +01:00
namespace zero.Architecture;
2021-11-19 16:11:12 +01:00
2021-11-22 14:29:22 +01:00
public class BlueprintChildInterceptor : Interceptor<ZeroEntity>, IBlueprintInterceptor
{
string configuredZeroDatabase;
2021-11-19 16:11:12 +01:00
2021-11-22 14:29:22 +01:00
public BlueprintChildInterceptor(IZeroContext context)
{
2021-11-22 16:03:02 +01:00
Gravity = -1;
2021-11-22 14:29:22 +01:00
configuredZeroDatabase = context.Options.For<RavenOptions>().Database;
}
2021-11-19 16:11:12 +01:00
2021-11-22 14:29:22 +01:00
/// <summary>
/// Only run this interceptor when the database is an app database
/// </summary>
public override bool CanHandle(InterceptorParameters args, Type modelType) => args.Context.Store.ResolvedDatabase != configuredZeroDatabase;
2021-11-19 16:11:12 +01:00
2021-11-22 14:29:22 +01:00
/// <inheritdoc />
public override Task<InterceptorResult<ZeroEntity>> Deleting(InterceptorParameters args, ZeroEntity model)
{
if (model.Blueprint == null)
{
2021-12-12 15:41:51 +01:00
return Task.FromResult<InterceptorResult<ZeroEntity>>(default);
2021-11-22 14:29:22 +01:00
}
2021-11-19 16:11:12 +01:00
2021-11-22 14:29:22 +01:00
InterceptorResult<ZeroEntity> result = new();
2021-11-26 15:47:11 +01:00
result.Result = Result<ZeroEntity>.Fail("@blueprint.errors.cannotDeleteChild");
2021-11-22 14:29:22 +01:00
return Task.FromResult(result);
}
}