Ejemplo n.º 1
0
        public static ContentType CreateSimpleContentType2(string alias, string name, IContentType parent = null, bool randomizeAliases = false, string propertyGroupAlias = "content", string propertyGroupName = "Content")
        {
            ContentTypeBuilder builder = CreateSimpleContentTypeHelper(alias, name, parent, randomizeAliases: randomizeAliases, propertyGroupAlias: propertyGroupAlias, propertyGroupName: propertyGroupName);

            builder.AddPropertyType()
            .WithAlias(RandomAlias("gen", randomizeAliases))
            .WithName("Gen")
            .WithSortOrder(1)
            .WithDataTypeId(-88)
            .WithMandatory(false)
            .WithDescription(string.Empty)
            .WithLabelOnTop(true)
            .Done();

            return((ContentType)builder.Build());
        }
Ejemplo n.º 2
0
        public override Content Build()
        {
            var      id                    = _id ?? 0;
            var      versionId             = _versionId ?? 0;
            Guid     key                   = _key ?? Guid.NewGuid();
            var      parentId              = _parentId ?? -1;
            IContent parent                = _parent ?? null;
            DateTime createDate            = _createDate ?? DateTime.Now;
            DateTime updateDate            = _updateDate ?? DateTime.Now;
            var      name                  = _name ?? Guid.NewGuid().ToString();
            var      creatorId             = _creatorId ?? 0;
            var      level                 = _level ?? 1;
            var      path                  = _path ?? $"-1,{id}";
            var      sortOrder             = _sortOrder ?? 0;
            var      trashed               = _trashed ?? false;
            var      culture               = _cultureInfo?.Name ?? null;
            var      propertyValues        = _propertyValues ?? null;
            var      propertyValuesCulture = _propertyValuesCulture ?? null;
            var      propertyValuesSegment = _propertyValuesSegment ?? null;

            if (_contentTypeBuilder is null && _contentType is null)
            {
                throw new InvalidOperationException("A content item cannot be constructed without providing a content type. Use AddContentType() or WithContentType().");
            }

            IContentType contentType = _contentType ?? _contentTypeBuilder.Build();

            Content content;

            if (parent != null)
            {
                content = new Content(name, parent, contentType, culture);
            }
            else
            {
                content = new Content(name, parentId, contentType, culture);
            }

            content.Id         = id;
            content.VersionId  = versionId;
            content.Key        = key;
            content.CreateDate = createDate;
            content.UpdateDate = updateDate;
            content.CreatorId  = creatorId;
            content.Level      = level;
            content.Path       = path;
            content.SortOrder  = sortOrder;
            content.Trashed    = trashed;

            foreach (KeyValuePair <string, string> cultureName in _cultureNames)
            {
                content.SetCultureName(cultureName.Value, cultureName.Key);
            }

            if (_propertyDataBuilder != null || propertyValues != null)
            {
                if (_propertyDataBuilder != null)
                {
                    IDictionary <string, object> propertyData = _propertyDataBuilder.Build();
                    foreach (KeyValuePair <string, object> keyValuePair in propertyData)
                    {
                        content.SetValue(keyValuePair.Key, keyValuePair.Value);
                    }
                }
                else
                {
                    content.PropertyValues(propertyValues, propertyValuesCulture, propertyValuesSegment);
                }

                content.ResetDirtyProperties(false);
            }

            if (_contentCultureInfosCollection is not null || _contentCultureInfosCollectionBuilder is not null)
            {
                ContentCultureInfosCollection contentCultureInfos =
                    _contentCultureInfosCollection ?? _contentCultureInfosCollectionBuilder.Build();
                content.PublishCultureInfos = contentCultureInfos;
            }

            return(content);
        }