protected override void PersistUpdatedItem(IContentType entity)
        {
            Mandate.That <Exception>(string.IsNullOrEmpty(entity.Alias) == false,
                                     () =>
            {
                var message =
                    string.Format(
                        "ContentType '{0}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
                        entity.Name);
                var exception = new Exception(message);

                LogHelper.Error <ContentTypeRepository>(message, exception);
                throw exception;
            });

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

            //Look up parent to get and set the correct Path if ParentId has changed
            if (((ICanBeDirty)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 ContentTypeFactory(NodeObjectTypeId);
            var dto     = factory.BuildDto(entity);

            PersistUpdatedBaseContentType(dto.ContentTypeDto, entity);

            //Look up DocumentType entries for updating - this could possibly be a "remove all, insert all"-approach
            Database.Delete <DocumentTypeDto>("WHERE contentTypeNodeId = @Id", new { Id = entity.Id });
            //Insert the updated DocumentTypeDto if a template exists
            if (dto.TemplateNodeId > 0)
            {
                Database.Insert(dto);
            }

            //Insert allowed Templates not including the default one, as that has already been inserted
            foreach (var template in entity.AllowedTemplates.Where(x => x != null && x.Id != dto.TemplateNodeId))
            {
                Database.Insert(new DocumentTypeDto {
                    ContentTypeNodeId = entity.Id, TemplateNodeId = template.Id, IsDefault = false
                });
            }

            ((ICanBeDirty)entity).ResetDirtyProperties();
        }
Esempio n. 2
0
        protected override void PersistUpdatedItem(IContentType entity)
        {
            ValidateAlias(entity);

            //Updates Modified date
            ((ContentType)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 ContentTypeFactory(NodeObjectTypeId);
            var dto     = factory.BuildDto(entity);

            PersistUpdatedBaseContentType(dto.ContentTypeDto, entity);

            //Look up DocumentType entries for updating - this could possibly be a "remove all, insert all"-approach
            Database.Delete <DocumentTypeDto>("WHERE contentTypeNodeId = @Id", new { Id = entity.Id });
            //Insert the updated DocumentTypeDto if a template exists
            if (dto.TemplateNodeId > 0)
            {
                Database.Insert(dto);
            }

            //Insert allowed Templates not including the default one, as that has already been inserted
            foreach (var template in entity.AllowedTemplates.Where(x => x != null && x.Id != dto.TemplateNodeId))
            {
                Database.Insert(new DocumentTypeDto {
                    ContentTypeNodeId = entity.Id, TemplateNodeId = template.Id, IsDefault = false
                });
            }

            entity.ResetDirtyProperties();
        }
        protected override void PersistNewItem(IContentType entity)
        {
            Mandate.That <Exception>(string.IsNullOrEmpty(entity.Alias) == false,
                                     () =>
            {
                var message =
                    string.Format(
                        "ContentType '{0}' cannot have an empty Alias. This is most likely due to invalid characters stripped from the Alias.",
                        entity.Name);
                var exception = new Exception(message);

                LogHelper.Error <ContentTypeRepository>(message, exception);
                throw exception;
            });

            ((ContentType)entity).AddingEntity();

            var factory = new ContentTypeFactory(NodeObjectTypeId);
            var dto     = factory.BuildDto(entity);

            PersistNewBaseContentType(dto.ContentTypeDto, entity);
            //Inserts data into the cmsDocumentType table if a template exists
            if (dto.TemplateNodeId > 0)
            {
                dto.ContentTypeNodeId = entity.Id;
                Database.Insert(dto);
            }

            //Insert allowed Templates not including the default one, as that has already been inserted
            foreach (var template in entity.AllowedTemplates.Where(x => x != null && x.Id != dto.TemplateNodeId))
            {
                Database.Insert(new DocumentTypeDto
                {
                    ContentTypeNodeId = entity.Id, TemplateNodeId = template.Id, IsDefault = false
                });
            }

            ((ICanBeDirty)entity).ResetDirtyProperties();
        }