public override MemberGroup Build()
        {
            var      id         = _id ?? 1;
            Guid     key        = _key ?? Guid.NewGuid();
            DateTime createDate = _createDate ?? DateTime.Now;
            DateTime updateDate = _updateDate ?? DateTime.Now;
            var      name       = _name ?? Guid.NewGuid().ToString();
            var      creatorId  = _creatorId ?? 1;

            var memberGroup = new MemberGroup
            {
                Id         = id,
                Key        = key,
                CreateDate = createDate,
                UpdateDate = updateDate,
                Name       = name,
                CreatorId  = creatorId,
            };

            if (_additionalDataBuilder != null)
            {
                IDictionary <string, object> additionalData = _additionalDataBuilder.Build();
                foreach (KeyValuePair <string, object> kvp in additionalData)
                {
                    memberGroup.AdditionalData.Add(kvp.Key, kvp.Value);
                }
            }

            return(memberGroup);
        }
Example #2
0
        public override Media Build()
        {
            var      id                    = _id ?? 0;
            Guid     key                   = _key ?? Guid.NewGuid();
            var      parentId              = _parentId ?? -1;
            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      propertyValues        = _propertyValues ?? null;
            var      propertyValuesCulture = _propertyValuesCulture ?? null;
            var      propertyValuesSegment = _propertyValuesSegment ?? null;

            if (_mediaTypeBuilder is null && _mediaType is null)
            {
                throw new InvalidOperationException("A media item cannot be constructed without providing a media type. Use AddMediaType() or WithMediaType().");
            }

            IMediaType mediaType = _mediaType ?? _mediaTypeBuilder.Build();

            var media = new Media(name, parentId, mediaType)
            {
                Id         = id,
                Key        = key,
                CreateDate = createDate,
                UpdateDate = updateDate,
                CreatorId  = creatorId,
                Level      = level,
                Path       = path,
                SortOrder  = sortOrder,
                Trashed    = trashed,
            };

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

                media.ResetDirtyProperties(false);
            }

            return(media);
        }
        public override DocumentEntitySlim Build()
        {
            var      id               = _id ?? 1;
            Guid     key              = _key ?? Guid.NewGuid();
            DateTime createDate       = _createDate ?? DateTime.Now;
            DateTime updateDate       = _updateDate ?? DateTime.Now;
            var      name             = _name ?? Guid.NewGuid().ToString();
            var      creatorId        = _creatorId ?? 1;
            var      level            = _level ?? 1;
            var      path             = _path ?? $"-1,{id}";
            var      sortOrder        = _sortOrder ?? 0;
            var      parentId         = _parentId ?? -1;
            var      icon             = _contentTypeIcon ?? string.Empty;
            var      thumbnail        = _contentTypeThumbnail ?? string.Empty;
            var      contentTypeAlias = _contentTypeAlias ?? string.Empty;
            var      hasChildren      = _hasChildren ?? false;
            var      published        = _published ?? false;

            var documentEntitySlim = new DocumentEntitySlim
            {
                Id                   = id,
                Key                  = key,
                CreateDate           = createDate,
                UpdateDate           = updateDate,
                Name                 = name,
                CreatorId            = creatorId,
                Level                = level,
                Path                 = path,
                SortOrder            = sortOrder,
                ParentId             = parentId,
                ContentTypeIcon      = icon,
                ContentTypeThumbnail = thumbnail,
                ContentTypeAlias     = contentTypeAlias,
                HasChildren          = hasChildren,
                Published            = published,
            };

            if (_additionalDataBuilder != null)
            {
                IDictionary <string, object> additionalData = _additionalDataBuilder.Build();
                foreach (KeyValuePair <string, object> kvp in additionalData)
                {
                    documentEntitySlim.AdditionalData.Add(kvp.Key, kvp.Value);
                }
            }

            return(documentEntitySlim);
        }
Example #4
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);
        }
Example #5
0
        public override Member Build()
        {
            var      id                     = _id ?? 0;
            Guid     key                    = _key ?? Guid.NewGuid();
            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      username               = _username ?? string.Empty;
            var      email                  = _email ?? string.Empty;
            var      rawPasswordValue       = _rawPasswordValue ?? string.Empty;
            var      failedPasswordAttempts = _failedPasswordAttempts ?? 0;
            var      isApproved             = _isApproved ?? false;
            var      isLockedOut            = _isLockedOut ?? false;
            DateTime lastLockoutDate        = _lastLockoutDate ?? DateTime.Now;
            DateTime lastLoginDate          = _lastLoginDate ?? DateTime.Now;
            DateTime lastPasswordChangeDate = _lastPasswordChangeDate ?? DateTime.Now;
            var      passwordConfig         = _passwordConfig ?? "{\"hashAlgorithm\":\"PBKDF2.ASPNETCORE.V3\"}";

            if (_memberTypeBuilder is null && _memberType is null)
            {
                throw new InvalidOperationException("A member cannot be constructed without providing a member type. Use AddMemberType() or WithMemberType().");
            }

            IMemberType memberType = _memberType ?? _memberTypeBuilder.Build();

            var member = new Member(name, email, username, rawPasswordValue, memberType)
            {
                Id                    = id,
                Key                   = key,
                CreateDate            = createDate,
                UpdateDate            = updateDate,
                CreatorId             = creatorId,
                Level                 = level,
                Path                  = path,
                SortOrder             = sortOrder,
                Trashed               = trashed,
                PasswordConfiguration = passwordConfig
            };

            if (_propertyIdsIncrementingFrom.HasValue)
            {
                var i = _propertyIdsIncrementingFrom.Value;
                foreach (IProperty property in member.Properties)
                {
                    property.Id = ++i;
                }
            }

            member.FailedPasswordAttempts = failedPasswordAttempts;
            member.IsApproved             = isApproved;
            member.IsLockedOut            = isLockedOut;
            member.LastLockoutDate        = lastLockoutDate;
            member.LastLoginDate          = lastLoginDate;
            member.LastPasswordChangeDate = lastPasswordChangeDate;

            if (_memberGroupsBuilder != null)
            {
                member.Groups = _memberGroupsBuilder.Build();
            }

            if (_additionalDataBuilder != null)
            {
                IDictionary <string, object> additionalData = _additionalDataBuilder.Build();
                foreach (KeyValuePair <string, object> kvp in additionalData)
                {
                    member.AdditionalData.Add(kvp.Key, kvp.Value);
                }
            }

            if (_propertyDataBuilder != null)
            {
                IDictionary <string, object> propertyData = _propertyDataBuilder.Build();
                foreach (KeyValuePair <string, object> kvp in propertyData)
                {
                    member.SetValue(kvp.Key, kvp.Value);
                }

                member.ResetDirtyProperties(false);
            }

            return(member);
        }