/// <inheritdoc/> public IEnumerable <TResource> BeforeDelete <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeDelete, resources, out var container, out var node)) { var relationships = node.RelationshipsToNextLayer.Select(p => p.Attribute).ToArray(); var targetResources = LoadDbValues(typeof(TResource), (IEnumerable <TResource>)node.UniqueResources, ResourceHook.BeforeDelete, relationships) ?? node.UniqueResources; var affected = new ResourceHashSet <TResource>(targetResources, node.LeftsToNextLayer()); IEnumerable <TResource> updated = container.BeforeDelete(affected, pipeline); node.UpdateUnique(updated); node.Reassign(_resourceFactory, resources); } // If we're deleting an article, we're implicitly affected any owners related to it. // Here we're loading all relations onto the to-be-deleted article // if for that relation the BeforeImplicitUpdateHook is implemented, // and this hook is then executed foreach (var entry in node.LeftsToNextLayerByRelationships()) { var rightType = entry.Key; var implicitTargets = entry.Value; FireForAffectedImplicits(rightType, implicitTargets, pipeline); } return(resources); }
/// <inheritdoc/> public IEnumerable <TResource> BeforeCreate <TResource>(IEnumerable <TResource> resources, ResourcePipeline pipeline) where TResource : class, IIdentifiable { if (GetHook(ResourceHook.BeforeCreate, resources, out var container, out var node)) { var affected = new ResourceHashSet <TResource>((HashSet <TResource>)node.UniqueResources, node.LeftsToNextLayer()); IEnumerable <TResource> updated = container.BeforeCreate(affected, pipeline); node.UpdateUnique(updated); node.Reassign(_resourceFactory, resources); } FireNestedBeforeUpdateHooks(pipeline, _traversalHelper.CreateNextLayer(node)); return(resources); }