예제 #1
0
        /// <summary>
        /// Method that will be called on an entity immediately before the item is saved by context
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="entry">The entry.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Data.DbContext dbContext, DbEntityEntry entry, EntityState state)
        {
            if (entry.State == EntityState.Deleted || entry.State == EntityState.Modified)
            {
                _preSaveChangesPersonAliasId = ( int? )(entry.OriginalValues?["PersonAliasId"]);
            }
            else
            {
                _preSaveChangesPersonAliasId = this.PersonAliasId;
            }

            var section = SharedPersonalLinkSectionCache.Get(this.SectionId);

            _preSaveChangesIsShared = section?.IsShared ?? false;
            base.PreSaveChanges(dbContext, entry, state);
        }
예제 #2
0
        /// <summary>
        /// Updates any Cache Objects that are associated with this entity
        /// </summary>
        /// <param name="entityState">State of the entity.</param>
        /// <param name="dbContext">The database context.</param>
        public void UpdateCache(EntityState entityState, Data.DbContext dbContext)
        {
            if (entityState == EntityState.Deleted)
            {
                // If the link section was deleted, the "ModifiedDateTime" of link orders need to be updated.
                // Otherwise, we won't be able to detect that the links have changed due to deleting a record.
                new PersonalLinkSectionOrderService(dbContext as RockContext).UpdateLinkOrdersModifiedDateTime(_preSaveChangesPersonAliasId);
            }

            if (_preSaveChangesIsShared || this.IsShared)
            {
                // If this is a shared section, update the SharedPersonalLinkSectionCache
                SharedPersonalLinkSectionCache.UpdateCachedEntity(this.Id, entityState);
                SharedPersonalLinkSectionCache.FlushLastModifiedDateTime();
            }

            // Since this change probably impacts the current person's links, flush the current person's link's ModifiedDateTime
            PersonalLinkService.PersonalLinksHelper.FlushPersonalLinksSessionDataLastModifiedDateTime();
        }
예제 #3
0
 /// <summary>
 /// Gets the cache object associated with this Entity
 /// </summary>
 /// <returns>IEntityCache.</returns>
 public IEntityCache GetCacheObject()
 {
     return(SharedPersonalLinkSectionCache.Get(this.Id));
 }