示例#1
0
 public void MarkStates(System.Data.Entity.EntityState state, params TEntity[] entity)
 {
     foreach (var item in entity)
     {
         bibliotecaContext.Entry <TEntity>(item).State = System.Data.Entity.EntityState.Unchanged;
     }
 }
        /// <summary>
        /// Pres the save.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            BinaryFileService binaryFileService = new BinaryFileService((RockContext)dbContext);
            var binaryFile = binaryFileService.Get(BinaryFileId);

            if (binaryFile != null)
            {
                if (state != System.Data.Entity.EntityState.Deleted)
                {
                    // if there is an binaryfile (image) associated with this, make sure that it is flagged as IsTemporary=False
                    if (binaryFile.IsTemporary)
                    {
                        binaryFile.IsTemporary = false;
                    }
                }
                else
                {
                    // if deleting, and there is an binaryfile (image) associated with this, make sure that it is flagged as IsTemporary=true
                    // so that it'll get cleaned up
                    if (!binaryFile.IsTemporary)
                    {
                        binaryFile.IsTemporary = true;
                    }
                }
            }
        }
        public void State_GetsMapped(EntityState revoState, System.Data.Entity.EntityState efState)
        {
            var entityEntry           = new InMemoryCrudRepository.EntityEntry(new Entity1(), revoState);
            InMemoryDbEntityEntry sut = new InMemoryDbEntityEntry(entityEntry);

            sut.State.Should().Be(efState);
        }
示例#4
0
文件: Page.cs 项目: ewin66/rockrms
        /// <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="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            if (state == System.Data.Entity.EntityState.Deleted)
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("PageId", this.Id);

                // since routes have a cascade delete relationship (their presave won't get called), delete routes from route table
                var routes = RouteTable.Routes;
                if (routes != null)
                {
                    foreach (var existingRoute in RouteTable.Routes.OfType <Route>().Where(r => r.PageIds().Contains(this.Id)))
                    {
                        var pageAndRouteIds = existingRoute.DataTokens["PageRoutes"] as List <Rock.Web.PageAndRouteId>;
                        pageAndRouteIds = pageAndRouteIds.Where(p => p.PageId != this.Id).ToList();
                        if (pageAndRouteIds.Any())
                        {
                            existingRoute.DataTokens["PageRoutes"] = pageAndRouteIds;
                        }
                        else
                        {
                            RouteTable.Routes.Remove(existingRoute);
                        }
                    }
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#5
0
        /// <summary>
        /// Pres the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(Rock.Data.DbContext dbContext, System.Data.Entity.EntityState state)
        {
            if (state == System.Data.Entity.EntityState.Deleted)
            {
                // manually clear any registrations using this workflow type
                foreach (var template in new RegistrationTemplateService(dbContext as RockContext)
                         .Queryable()
                         .Where(r =>
                                r.RegistrationWorkflowTypeId.HasValue &&
                                r.RegistrationWorkflowTypeId.Value == this.Id))
                {
                    template.RegistrationWorkflowTypeId = null;
                }

                foreach (var instance in new RegistrationInstanceService(dbContext as RockContext)
                         .Queryable()
                         .Where(r =>
                                r.RegistrationWorkflowTypeId.HasValue &&
                                r.RegistrationWorkflowTypeId.Value == this.Id))
                {
                    instance.RegistrationWorkflowTypeId = null;
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#6
0
        /// <summary>
        /// Pres the save.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            if (state == System.Data.Entity.EntityState.Deleted)
            {
                ChildContentChannels.Clear();
            }

            // clean up the index
            if (state == System.Data.Entity.EntityState.Deleted && IsIndexEnabled)
            {
                this.DeleteIndexedDocumentsByContentChannel(Id);
            }
            else if (state == System.Data.Entity.EntityState.Modified)
            {
                // check if indexing is enabled
                var changeEntry = dbContext.ChangeTracker.Entries <ContentChannel>().Where(a => a.Entity == this).FirstOrDefault();
                if (changeEntry != null)
                {
                    var originalIndexState = (bool)changeEntry.OriginalValues["IsIndexEnabled"];

                    if (originalIndexState == true && IsIndexEnabled == false)
                    {
                        // clear out index items
                        this.DeleteIndexedDocumentsByContentChannel(Id);
                    }
                    else if (IsIndexEnabled == true)
                    {
                        // if indexing is enabled then bulk index - needed as an attribute could have changed from IsIndexed
                        BulkIndexDocumentsByContentChannel(Id);
                    }
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#7
0
        /// <summary>
        /// Execute additional steps for TestItem
        /// </summary>
        /// <param name="state">Entity's current state</param>
        /// <param name="entityObject">Entity</param>
        /// <param name="originalEntity">Unmodified entity</param>
        public void Execute(System.Data.Entity.EntityState state, object entityObject, object originalEntity)
        {
            TestItem      entity   = (TestItem)entityObject;
            TestItem      dbEntity = originalEntity as TestItem;
            BlayerContext ctx      = entity.Context;

            switch (state)
            {
            // If the entity was added (data creation)
            case System.Data.Entity.EntityState.Added:
            {
            }
            break;

            // If the entity was removed (data removal)
            case System.Data.Entity.EntityState.Deleted:
            {
                // testing logical removal
                entity.WillBeDeleted = false;
                entity.Name          = "Rmoved";
            }
            break;

            // If the entity was updated (data update)
            case System.Data.Entity.EntityState.Modified:
            {
            }
            break;

            default:
                break;
            }
        }
示例#8
0
 /// <summary>
 /// Pres the save.
 /// </summary>
 /// <param name="dbContext">The database context.</param>
 /// <param name="state">The state.</param>
 public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
 {
     if (state == System.Data.Entity.EntityState.Deleted)
     {
         ChildGroupTypes.Clear();
     }
 }
示例#9
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(System.Data.Entity.EntityState entityState, Rock.Data.DbContext dbContext)
        {
            AttributeCache cacheAttribute = AttributeCache.Get(this.AttributeId, dbContext as RockContext);

            if (cacheAttribute == null)
            {
                return;
            }

            if (this.EntityId.HasValue && cacheAttribute.EntityTypeId.HasValue)
            {
                EntityTypeCache entityType = EntityTypeCache.Get(cacheAttribute.EntityTypeId.Value, dbContext as RockContext);

                if (entityType?.HasEntityCache() == true)
                {
                    entityType.FlushCachedItem(this.EntityId.Value);
                }
            }

            if ((!cacheAttribute.EntityTypeId.HasValue || cacheAttribute.EntityTypeId.Value == 0) && string.IsNullOrEmpty(cacheAttribute.EntityTypeQualifierColumn) && string.IsNullOrEmpty(cacheAttribute.EntityTypeQualifierValue))
            {
                // Update GlobalAttributes if one of the values changed
                GlobalAttributesCache.Remove();
            }
        }
示例#10
0
        private static void OnStateChangeCallBack(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            System.Data.Entity.EntityState s = (System.Data.Entity.EntityState)e.NewValue;
            toolBar_Mini toolBar_Mini        = sender as toolBar_Mini;

            toolBar_Mini.OnStatePropertyChanged(s);
        }
示例#11
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="state">The state.</param>
 public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
 {
     if (state == System.Data.Entity.EntityState.Deleted)
     {
         Dictionary <string, object> parameters = new Dictionary <string, object>();
         parameters.Add("PageId", this.Id);
         Rock.Data.DbService.ExecuteCommand("spCore_PageViewNullPageId", System.Data.CommandType.StoredProcedure, parameters);
     }
 }
示例#12
0
        /// <summary>
        /// Updates the formatted number prior to update.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            if (state == System.Data.Entity.EntityState.Added || state == System.Data.Entity.EntityState.Modified)
            {
                NumberFormatted = PhoneNumber.FormattedNumber(CountryCode, Number);
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#13
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(System.Data.Entity.EntityState entityState, Rock.Data.DbContext dbContext)
        {
            var workflowTypeId = WorkflowActivityTypeCache.Get(this.ActivityTypeId, dbContext as RockContext)?.WorkflowTypeId;

            if (workflowTypeId.HasValue)
            {
                WorkflowTypeCache.UpdateCachedEntity(workflowTypeId.Value, System.Data.Entity.EntityState.Modified);
            }

            WorkflowActivityTypeCache.UpdateCachedEntity(this.ActivityTypeId, System.Data.Entity.EntityState.Modified);
            WorkflowActionTypeCache.UpdateCachedEntity(this.Id, entityState);
        }
示例#14
0
 /// <summary>
 /// Pres the save changes.
 /// </summary>
 /// <param name="dbContext">The database context.</param>
 /// <param name="state">The state.</param>
 public override void PreSaveChanges(Rock.Data.DbContext dbContext, System.Data.Entity.EntityState state)
 {
     if (ImageId.HasValue)
     {
         BinaryFileService binaryFileService = new BinaryFileService((RockContext)dbContext);
         var binaryFile = binaryFileService.Get(ImageId.Value);
         if (binaryFile != null && binaryFile.IsTemporary)
         {
             binaryFile.IsTemporary = false;
         }
     }
 }
示例#15
0
        /// <summary>
        /// Pres the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            var calEvent = GetCalenderEvent();

            if (calEvent != null)
            {
                EffectiveStartDate = calEvent.DTStart != null ? calEvent.DTStart.Value.Date : (DateTime?)null;
                EffectiveEndDate   = calEvent.DTEnd != null ? calEvent.DTEnd.Value.Date : (DateTime?)null;
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#16
0
 /// <summary>
 /// Pres the save.
 /// </summary>
 /// <param name="dbContext">The database context.</param>
 /// <param name="state">The state.</param>
 public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
 {
     if (state == System.Data.Entity.EntityState.Deleted)
     {
         // since images have a cascade delete relationship, make sure the PreSaveChanges gets called
         var childImages = new FinancialTransactionImageService(dbContext as RockContext).Queryable().Where(a => a.TransactionId == this.Id);
         foreach (var image in childImages)
         {
             image.PreSaveChanges(dbContext, state);
         }
     }
 }
示例#17
0
 protected virtual void OnStatePropertyChanged(System.Data.Entity.EntityState State)
 {
     if (State == System.Data.Entity.EntityState.Added || State == System.Data.Entity.EntityState.Modified)
     {
         IsEditable     = true;
         Edit_IsEnabled = false;
     }
     else
     {
         IsEditable     = false;
         Edit_IsEnabled = true;
     }
 }
示例#18
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(System.Data.Entity.EntityState entityState, Rock.Data.DbContext dbContext)
        {
            var cachedDefinedValues = DefinedTypeCache.Get(this.Id, (RockContext)dbContext)?.DefinedValues;

            if (cachedDefinedValues?.Any() == true)
            {
                foreach (var cachedDefinedValue in cachedDefinedValues)
                {
                    DefinedValueCache.UpdateCachedEntity(cachedDefinedValue.Id, System.Data.Entity.EntityState.Detached);
                }
            }

            DefinedTypeCache.UpdateCachedEntity(this.Id, entityState);
        }
示例#19
0
        /// <summary>
        /// Updates the formatted number prior to update.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            if (state == System.Data.Entity.EntityState.Added || state == System.Data.Entity.EntityState.Modified)
            {
                if (string.IsNullOrEmpty(CountryCode))
                {
                    CountryCode = PhoneNumber.DefaultCountryCode();
                }

                NumberFormatted = PhoneNumber.FormattedNumber(CountryCode, Number);
                Number          = PhoneNumber.CleanNumber(NumberFormatted);
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#20
0
        /// <summary>
        /// Pres the save changes.
        /// </summary>
        /// <param name="dbContext">The database context.</param>
        /// <param name="state">The state.</param>
        public override void PreSaveChanges(DbContext dbContext, System.Data.Entity.EntityState state)
        {
            string action = string.Empty;

            if (state == System.Data.Entity.EntityState.Added)
            {
                action = "Added to group.";
                if (!this.DateTimeAdded.HasValue)
                {
                    this.DateTimeAdded = RockDateTime.Now;
                }
            }
            else if (state == System.Data.Entity.EntityState.Deleted)
            {
                action = "Removed from group.";
            }

            if (!string.IsNullOrWhiteSpace(action))
            {
                var rockContext = (RockContext)dbContext;

                var group = this.Group;
                if (group == null)
                {
                    group = new GroupService(rockContext).Get(this.GroupId);
                }

                if (group != null)
                {
                    var personEntityTypeId        = EntityTypeCache.Read("Rock.Model.Person").Id;
                    var groupEntityTypeId         = EntityTypeCache.Read("Rock.Model.Group").Id;
                    var groupMembershipCategoryId = CategoryCache.Read(Rock.SystemGuid.Category.HISTORY_PERSON_GROUP_MEMBERSHIP.AsGuid(), rockContext).Id;

                    new HistoryService(rockContext).Add(new History
                    {
                        EntityTypeId        = personEntityTypeId,
                        CategoryId          = groupMembershipCategoryId,
                        EntityId            = this.PersonId,
                        Summary             = action,
                        Caption             = group.Name,
                        RelatedEntityTypeId = groupEntityTypeId,
                        RelatedEntityId     = this.GroupId
                    });
                }
            }

            base.PreSaveChanges(dbContext, state);
        }
示例#21
0
        private void ChangeEntityState(T entity, System.Data.Entity.EntityState State)
        {
            c = new Context();
            var set            = c.Set <T>();
            T   attachedEntity = set.Find(entity.Id);

            if (attachedEntity != null)
            {
                var attachedEntry = c.Entry(attachedEntity);
                attachedEntry.CurrentValues.SetValues(entity);
                attachedEntry.State = State;
            }
            else
            {
                c.Entry <T>(entity).State = State;
            }
        }
        public virtual void Update(T entity)
        {
            if (entity == null)
            {
                throw (new System.ArgumentNullException("entity"));
            }

            //#if DEBUG
            //#endif

            // **************************************************
            // Just For Debug!
            // **************************************************
            System.Data.Entity.EntityState oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************

            if (oEntityState == System.Data.Entity.EntityState.Detached)
            {
                DbSet.Attach(entity);
            }

            // **************************************************
            // Just For Debug!
            // **************************************************
            oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************

            DatabaseContext.Entry(entity).State =
                System.Data.Entity.EntityState.Modified;

            // **************************************************
            // Just For Debug!
            // **************************************************
            oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************
        }
示例#23
0
 public object Convert(object value, Type targetType, object ConverterParameter, System.Globalization.CultureInfo culture)
 {
     if (value != null)
     {
         System.Data.Entity.EntityState state = (System.Data.Entity.EntityState)value;
         if (state == System.Data.Entity.EntityState.Added || state == System.Data.Entity.EntityState.Modified)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(true);
     }
 }
        public override bool Modificar(Paciente entity)
        {
            Contexto context  = new Contexto();
            Paciente anterior = this.Buscar(entity.Id_Paciente);

            //Verificando los modificados o agregados
            foreach (AnalisisDetalle elementoAnterior in anterior.AnalisisDetalle)
            {
                AnalisisDetalle detalle = entity.AnalisisDetalle.Find(x => x.Id_Analisis_Detalle == elementoAnterior.Id_Analisis_Detalle || x.Id_Analisis_Detalle == 0);
                RepositorioBase <TipoAnalisis> repositorioTipo = new RepositorioBase <TipoAnalisis>();
                if (detalle != null)
                {
                    System.Data.Entity.EntityState newState = detalle.Id_Analisis_Detalle <= 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                    TipoAnalisis tipoAnalisis = repositorioTipo.Buscar(detalle.Id_Tipo_Analisis);
                    if (newState == System.Data.Entity.EntityState.Added)
                    {
                        tipoAnalisis.Cantidad_Realizada += 1;
                    }
                    else
                    {
                        if (elementoAnterior.Id_Tipo_Analisis != detalle.Id_Tipo_Analisis)
                        {
                            TipoAnalisis TipoAnterior = repositorioTipo.Buscar(elementoAnterior.Id_Tipo_Analisis);
                            TipoAnterior.Cantidad_Realizada -= 1;
                            new RepositorioBase <TipoAnalisis>().Modificar(TipoAnterior);
                            TipoAnalisis actual = repositorioTipo.Buscar(detalle.Id_Tipo_Analisis);
                            actual.Cantidad_Realizada += 1;
                            new RepositorioBase <TipoAnalisis>().Modificar(actual);
                        }
                    }
                    context.Entry(elementoAnterior).State = newState;
                }
                else
                {
                    TipoAnalisis TipoAnterior = repositorioTipo.Buscar(elementoAnterior.Id_Tipo_Analisis);
                    TipoAnterior.Cantidad_Realizada -= 1;
                    new RepositorioBase <TipoAnalisis>().Modificar(TipoAnterior);
                    context.Entry(elementoAnterior).State = System.Data.Entity.EntityState.Deleted;
                }
            }
            context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
            return(context.SaveChanges() > 0);
        }
示例#25
0
        /// <summary>
        /// Attach or update storage entity
        /// </summary>
        protected void AttachOrUpdate(object entity, System.Data.Entity.EntityState state)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(entity)}", "Provided storage entity is null.");
            }

            ObjectContext context = ((IObjectContextAdapter)_context).ObjectContext;
            EntityKey     key     = context.CreateEntityKey(PluralEntity(entity), entity);

            if (context.ObjectStateManager.TryGetObjectStateEntry(key, out ObjectStateEntry entry))
            {
                entry.ApplyCurrentValues(entity);
            }
            else
            {
                _context.Entry(entity).State = state;
            }
        }
示例#26
0
        /// <summary>
        /// Updates the specified question.
        /// </summary>
        /// <param name="model">The question.</param>
        public override void Update(Model.Entities.Question model)
        {
            // Getting existing Question
            Repository.Question existingEntity = Context.Set <Repository.Question>().Find(ObjectMapper.GetEntityIdentifier <Model.Entities.Question>(model));

            // deleting existing questions choices
            List <QuestionChoice> existingQuestionChoices = (from qCh in Context.Set <QuestionChoice>()
                                                             .Where(cr => cr.Question_Id == model.Id)
                                                             select qCh).ToList <QuestionChoice>();

            foreach (Repository.QuestionChoice questionChoice in existingQuestionChoices)
            {
                Context.Set <Repository.QuestionChoice>().Remove(questionChoice);
            }

            // Detach existing Entity
            System.Data.Entity.EntityState existingEntityState = Context.Entry <Repository.Question>(existingEntity).State;
            if (existingEntityState != System.Data.Entity.EntityState.Detached)
            {
                Context.Entry <Repository.Question>(existingEntity).State = System.Data.Entity.EntityState.Detached;
            }

            // Getting the updated Question
            Repository.Question updatedEntity = ObjectMapper.Map <Model.Entities.Question, Repository.Question>(model);

            //adding the question choices of the updated question
            foreach (Repository.QuestionChoice questionChoice in updatedEntity.QuestionChoices)
            {
                Context.Set <Repository.QuestionChoice>().Add(questionChoice);
            }


            //changing to modified state the updated entity
            System.Data.Entity.EntityState updatedEntityState = Context.Entry <Repository.Question>(updatedEntity).State;
            if (updatedEntityState == System.Data.Entity.EntityState.Detached)
            {
                Context.Entry <Repository.Question>(updatedEntity).State = System.Data.Entity.EntityState.Modified;
            }


            Context.SaveChanges();
        }
 public virtual void SetStateForEntity <T>(T entity, System.Data.Entity.EntityState state) where T : class
 {
     if (state == System.Data.Entity.EntityState.Modified)
     {
         if (entity is Data.Goal)
         {
             var goal = entity as Data.Goal;
             if (this.Goals.Any(i => i.Id == goal.Id))
             {
                 var currentGoal = this.Goals.First(i => i.Id == goal.Id);
                 this.Goals.Remove(currentGoal);
                 this.Goals.Add(goal);
             }
             else
             {
                 throw new ApplicationException("Entity not found.");
             }
         }
     }
 }
        public virtual void Delete(T entity)
        {
            if (entity == null)
            {
                throw (new System.ArgumentNullException("entity"));
            }

            // **************************************************
            // Just For Debug!
            // **************************************************
            System.Data.Entity.EntityState oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************

            if (oEntityState == System.Data.Entity.EntityState.Detached)
            {
                DbSet.Attach(entity);
            }

            // **************************************************
            // Just For Debug!
            // **************************************************
            oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************

            DbSet.Remove(entity);

            // **************************************************
            // Just For Debug!
            // **************************************************
            oEntityState =
                DatabaseContext.Entry(entity).State;
            // **************************************************
            // /Just For Debug!
            // **************************************************
        }
        /// <summary>
        /// Converts the native EF6 entity state enumeration into the Rock
        /// <see cref="EntityContextState"/> enumeration.
        /// </summary>
        /// <param name="entityState">State of the entity.</param>
        /// <returns>The entity state as a Rock enumeration value.</returns>
        public static EntityContextState ToEntityContextState(this System.Data.Entity.EntityState entityState)
        {
            switch (entityState)
            {
            case System.Data.Entity.EntityState.Unchanged:
                return(EntityContextState.Unchanged);

            case System.Data.Entity.EntityState.Added:
                return(EntityContextState.Added);

            case System.Data.Entity.EntityState.Deleted:
                return(EntityContextState.Deleted);

            case System.Data.Entity.EntityState.Modified:
                return(EntityContextState.Modified);

            case System.Data.Entity.EntityState.Detached:
            default:
                return(EntityContextState.Detached);
            }
        }
示例#30
0
文件: Page.cs 项目: ewin66/rockrms
        /// <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(System.Data.Entity.EntityState entityState, Rock.Data.DbContext dbContext)
        {
            var oldPageCache = PageCache.Get(this.Id, (RockContext)dbContext);

            if (oldPageCache != null)
            {
                oldPageCache.RemoveChildPages();
            }

            PageCache.UpdateCachedEntity(this.Id, entityState);

            if (this.ParentPageId.HasValue)
            {
                PageCache.UpdateCachedEntity(this.ParentPageId.Value, System.Data.Entity.EntityState.Detached);
            }

            if (_originalParentPageId.HasValue && _originalParentPageId != this.ParentPageId)
            {
                PageCache.UpdateCachedEntity(_originalParentPageId.Value, System.Data.Entity.EntityState.Detached);
            }
        }