Esempio n. 1
0
        protected override void PersistUpdatedItem(IDictionaryItem entity)
        {
            ((EntityBase)entity).UpdatingEntity();

            foreach (var translation in entity.Translations)
            {
                translation.Value = translation.Value.ToValidXmlString();
            }

            var dto = DictionaryItemFactory.BuildDto(entity);

            Database.Update(dto);

            foreach (var translation in entity.Translations)
            {
                var textDto = DictionaryTranslationFactory.BuildDto(translation, entity.Key);
                if (translation.HasIdentity)
                {
                    Database.Update(textDto);
                }
                else
                {
                    translation.Id  = Convert.ToInt32(Database.Insert(textDto));
                    translation.Key = entity.Key;
                }
            }

            entity.ResetDirtyProperties();

            //Clear the cache entries that exist by uniqueid/item key
            IsolatedCache.ClearCacheItem(RepositoryCacheKeys.GetKey <IDictionaryItem>(entity.ItemKey));
            IsolatedCache.ClearCacheItem(RepositoryCacheKeys.GetKey <IDictionaryItem>(entity.Key));
        }
        protected override void PersistDeletedItem(ILanguage entity)
        {
            base.PersistDeletedItem(entity);

            //Clear the cache entries that exist by key/iso
            IsolatedCache.ClearCacheItem(GetCacheIdKey <ILanguage>(entity.IsoCode));
            IsolatedCache.ClearCacheItem(GetCacheIdKey <ILanguage>(entity.CultureName));
        }
Esempio n. 3
0
        /// <inheritdoc />
        protected override void PersistUpdatedItem(IConsent entity)
        {
            ((EntityBase)entity).UpdatingEntity();

            var dto = ConsentFactory.BuildDto(entity);

            Database.Update(dto);
            entity.ResetDirtyProperties();

            IsolatedCache.ClearCacheItem(RepositoryCacheKeys.GetKey <IConsent>(entity.Id));
        }
        protected override void PersistDeletedItem(IDictionaryItem entity)
        {
            RecursiveDelete(entity.Key);

            Database.Delete <LanguageTextDto>("WHERE UniqueId = @Id", new { Id = entity.Key });
            Database.Delete <DictionaryDto>("WHERE id = @Id", new { Id = entity.Key });

            //Clear the cache entries that exist by uniqueid/item key
            IsolatedCache.ClearCacheItem(GetCacheIdKey <IDictionaryItem>(entity.ItemKey));
            IsolatedCache.ClearCacheItem(GetCacheIdKey <IDictionaryItem>(entity.Key));

            entity.DeletedDate = DateTime.Now;
        }
        protected override void PersistUpdatedItem(IDataTypeDefinition entity)
        {
            entity.Name = EnsureUniqueNodeName(entity.Name, entity.Id);

            //Cannot change to a duplicate alias
            var exists = Database.ExecuteScalar <int>(@"SELECT COUNT(*) FROM cmsDataType
INNER JOIN umbracoNode ON cmsDataType.nodeId = umbracoNode.id
WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + @"= @name
AND umbracoNode.id <> @id",
                                                      new { id = entity.Id, name = entity.Name });

            if (exists > 0)
            {
                throw new DuplicateNameException("A data type with the name " + entity.Name + " already exists");
            }

            //Updates Modified date
            ((DataTypeDefinition)entity).UpdatingEntity();

            //Look up parent to get and set the correct Path if ParentId has changed
            if (entity.IsPropertyDirty("ParentId"))
            {
                var parent = Database.First <NodeDto>("WHERE id = @ParentId", new { ParentId = entity.ParentId });
                entity.Path  = string.Concat(parent.Path, ",", entity.Id);
                entity.Level = parent.Level + 1;
                var maxSortOrder =
                    Database.ExecuteScalar <int>(
                        "SELECT coalesce(max(sortOrder),0) FROM umbracoNode WHERE parentid = @ParentId AND nodeObjectType = @NodeObjectType",
                        new { ParentId = entity.ParentId, NodeObjectType = NodeObjectTypeId });
                entity.SortOrder = maxSortOrder + 1;
            }

            var factory = new DataTypeDefinitionFactory(NodeObjectTypeId);
            //Look up DataTypeDefinition entry to get Primary for updating the DTO
            var dataTypeDto = Database.SingleOrDefault <DataTypeDto>("WHERE nodeId = @Id", new { Id = entity.Id });

            factory.SetPrimaryKey(dataTypeDto.PrimaryKey);
            var dto = factory.BuildDto(entity);

            //Updates the (base) node data - umbracoNode
            var nodeDto = dto.NodeDto;

            Database.Update(nodeDto);
            Database.Update(dto);

            //NOTE: This is a special case, we need to clear the custom cache for pre-values here so they are not stale if devs
            // are querying for them in the Saved event (before the distributed call cache is clearing it)
            IsolatedCache.ClearCacheItem(GetPrefixedCacheKey(entity.Id));

            entity.ResetDirtyProperties();
        }
        protected override void PersistUpdatedItem(ILanguage entity)
        {
            ((Entity)entity).UpdatingEntity();

            var factory = new LanguageFactory();
            var dto     = factory.BuildDto(entity);

            Database.Update(dto);

            entity.ResetDirtyProperties();

            //Clear the cache entries that exist by key/iso
            IsolatedCache.ClearCacheItem(GetCacheIdKey <ILanguage>(entity.IsoCode));
            IsolatedCache.ClearCacheItem(GetCacheIdKey <ILanguage>(entity.CultureName));
        }
        private void RecursiveDelete(Guid parentId)
        {
            var list = Database.Fetch <DictionaryDto>("WHERE parent = @ParentId", new { ParentId = parentId });

            foreach (var dto in list)
            {
                RecursiveDelete(dto.UniqueId);

                Database.Delete <LanguageTextDto>("WHERE UniqueId = @Id", new { Id = dto.UniqueId });
                Database.Delete <DictionaryDto>("WHERE id = @Id", new { Id = dto.UniqueId });

                //Clear the cache entries that exist by uniqueid/item key
                IsolatedCache.ClearCacheItem(GetCacheIdKey <IDictionaryItem>(dto.Key));
                IsolatedCache.ClearCacheItem(GetCacheIdKey <IDictionaryItem>(dto.UniqueId));
            }
        }