Esempio n. 1
0
        public void HandleEvent(PreActionHookEvent eventMessage)
        {
            var entries = eventMessage.ModifiedEntries;

            if (!entries.Any() || !_preHooks.Any())
            {
                return;
            }

            foreach (var entry in entries)
            {
                var e        = entry; // Prevents access to modified closure
                var preHooks = GetPreHookInstancesFor(e.Entity.GetType());
                foreach (var hook in preHooks)
                {
                    if (hook.HookStates == e.PreSaveState && hook.RequiresValidation == eventMessage.RequiresValidation)
                    {
                        var metadata = new HookEntityMetadata(e.PreSaveState);
                        hook.HookObject(e.Entity, metadata);

                        if (metadata.HasStateChanged)
                        {
                            e.PreSaveState = metadata.State;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void HandleEvent(PostActionHookEvent eventMessage)
        {
            var entries = eventMessage.ModifiedEntries;

            if (!entries.Any() || !_postHooks.Any())
            {
                return;
            }

            foreach (var entry in entries)
            {
                var e         = entry; // Prevents access to modified closure
                var postHooks = GetPostHookInstancesFor(e.Entity.GetType());
                foreach (var hook in postHooks)
                {
                    if (hook.HookStates == e.PreSaveState)
                    {
                        var metadata = new HookEntityMetadata(e.PreSaveState);
                        hook.HookObject(e.Entity, metadata);
                    }
                }
            }
        }