예제 #1
0
        internal MemberTypeReadOnlyDto Map(MemberTypeReadOnlyDto a, PropertyTypeReadOnlyDto p, PropertyTypeGroupReadOnlyDto g)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (a == null)
            {
                return(Current);
            }

            // Is this the same MemberTypeReadOnlyDto as the current one we're processing
            if (Current != null && Current.UniqueId == a.UniqueId)
            {
                //This property may already be added so we need to check for that
                if (p.Id.HasValue && Current.PropertyTypes.Any(x => x.Id == p.Id.Value) == false)
                {
                    // Add this PropertyTypeReadOnlyDto to the current MemberTypeReadOnlyDto's collection
                    Current.PropertyTypes.Add(p);
                }

                if (g.Id.HasValue && Current.PropertyTypeGroups != null && Current.PropertyTypeGroups.Any(x => x.Id == g.Id.Value) == false)
                {
                    Current.PropertyTypeGroups.Add(g);
                }

                // Return null to indicate we're not done with this MemberTypeReadOnlyDto yet
                return(null);
            }

            // This is a different MemberTypeReadOnlyDto to the current one, or this is the
            // first time through and we don't have a Tab yet

            // Save the current MemberTypeReadOnlyDto
            var prev = Current;

            // Setup the new current MemberTypeReadOnlyDto
            Current = a;
            Current.PropertyTypes = new List <PropertyTypeReadOnlyDto>();
            //this can be null since we are doing a left join
            if (p.Id.HasValue)
            {
                Current.PropertyTypes.Add(p);
            }

            Current.PropertyTypeGroups = new List <PropertyTypeGroupReadOnlyDto>();
            if (g.Id.HasValue)
            {
                Current.PropertyTypeGroups.Add(g);
            }

            // Return the now populated previous MemberTypeReadOnlyDto (or null if first time through)
            return(prev);
        }
예제 #2
0
        public IMemberType BuildEntity(MemberTypeReadOnlyDto dto)
        {
            var standardPropertyTypes = Constants.Conventions.Member.GetStandardPropertyTypeStubs();

            var memberType = new MemberType(dto.ParentId)
            {
                Alias               = dto.Alias,
                AllowedAsRoot       = dto.AllowAtRoot,
                CreateDate          = dto.CreateDate,
                CreatorId           = dto.UserId.HasValue ? dto.UserId.Value : 0,
                Description         = dto.Description,
                Icon                = dto.Icon,
                Id                  = dto.NodeId,
                IsContainer         = dto.IsContainer,
                Key                 = dto.UniqueId.Value,
                Level               = dto.Level,
                Name                = dto.Text,
                Path                = dto.Path,
                SortOrder           = dto.SortOrder,
                Thumbnail           = dto.Thumbnail,
                Trashed             = dto.Trashed,
                UpdateDate          = dto.CreateDate,
                AllowedContentTypes = Enumerable.Empty <ContentTypeSort>()
            };

            var propertyTypeGroupCollection = GetPropertyTypeGroupCollection(dto, memberType, standardPropertyTypes);

            memberType.PropertyGroups = propertyTypeGroupCollection;

            var propertyTypes = GetPropertyTypes(dto, memberType, standardPropertyTypes);

            //By Convention we add 9 stnd PropertyTypes - This is only here to support loading of types that didn't have these conventions before.
            foreach (var standardPropertyType in standardPropertyTypes)
            {
                if (dto.PropertyTypes.Any(x => x.Alias.Equals(standardPropertyType.Key)))
                {
                    continue;
                }

                //Add the standard PropertyType to the current list
                propertyTypes.Add(standardPropertyType.Value);

                //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType
                memberType.MemberTypePropertyTypes.Add(standardPropertyType.Key,
                                                       new MemberTypePropertyProfileAccess(false, false));
            }
            memberType.PropertyTypes = propertyTypes;

            return(memberType);
        }
        private static List <PropertyType> GetPropertyTypes(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary <string, PropertyType> standardProps)
        {
            //Find PropertyTypes that does not belong to a PropertyTypeGroup
            var propertyTypes = new List <PropertyType>();

            foreach (var typeDto in dto.PropertyTypes.Where(x => (x.PropertyTypeGroupId.HasValue == false || x.PropertyTypeGroupId.Value == 0) && x.Id.HasValue))
            {
                //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType
                memberType.MemberTypePropertyTypes.Add(typeDto.Alias,
                                                       new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit, typeDto.IsSensitive));

                //ensures that any built-in membership properties have their correct dbtype assigned no matter
                //what the underlying data type is
                var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty(
                    typeDto.Alias,
                    typeDto.DbType.EnumParse <ValueStorageType>(true),
                    standardProps);

                var propertyType = new PropertyType(
                    typeDto.PropertyEditorAlias,
                    propDbType.Result,
                    //This flag tells the property type that it has an explicit dbtype and that it cannot be changed
                    // which is what we want for the built-in properties.
                    propDbType.Success,
                    typeDto.Alias)
                {
                    DataTypeId       = typeDto.DataTypeId,
                    Description      = typeDto.Description,
                    Id               = typeDto.Id.Value,
                    Mandatory        = typeDto.Mandatory,
                    Name             = typeDto.Name,
                    SortOrder        = typeDto.SortOrder,
                    ValidationRegExp = typeDto.ValidationRegExp,
                    PropertyGroupId  = null,
                    CreateDate       = dto.CreateDate,
                    UpdateDate       = dto.CreateDate,
                    Key              = typeDto.UniqueId
                };

                propertyTypes.Add(propertyType);
            }
            return(propertyTypes);
        }
        private IEnumerable <MemberTypeReadOnlyDto> MapOneToManies(IEnumerable <MemberTypeReadOnlyDto> dtos)
        {
            MemberTypeReadOnlyDto acc = null;

            foreach (var dto in dtos)
            {
                if (acc == null)
                {
                    acc = dto;
                }
                else if (acc.UniqueId == dto.UniqueId)
                {
                    var prop  = dto.PropertyTypes.SingleOrDefault();
                    var group = dto.PropertyTypeGroups.SingleOrDefault();

                    if (prop != null && prop.Id.HasValue && acc.PropertyTypes.Any(x => x.Id == prop.Id.Value) == false)
                    {
                        acc.PropertyTypes.Add(prop);
                    }

                    if (group != null && group.Id.HasValue && acc.PropertyTypeGroups.Any(x => x.Id == group.Id.Value) == false)
                    {
                        acc.PropertyTypeGroups.Add(group);
                    }
                }
                else
                {
                    yield return(acc);

                    acc = dto;
                }
            }

            if (acc != null)
            {
                yield return(acc);
            }
        }
        private static PropertyGroupCollection GetPropertyTypeGroupCollection(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary <string, PropertyType> standardProps)
        {
            // see PropertyGroupFactory, repeating code here...

            var propertyGroups = new PropertyGroupCollection();

            foreach (var groupDto in dto.PropertyTypeGroups.Where(x => x.Id.HasValue))
            {
                var group = new PropertyGroup(MemberType.IsPublishingConst);

                // if the group is defined on the current member type,
                // assign its identifier, else it will be zero
                if (groupDto.ContentTypeNodeId == memberType.Id)
                {
                    // note: no idea why Id is nullable here, but better check
                    if (groupDto.Id.HasValue == false)
                    {
                        throw new Exception("GroupDto.Id has no value.");
                    }
                    group.Id = groupDto.Id.Value;
                }

                group.Key           = groupDto.UniqueId;
                group.Name          = groupDto.Text;
                group.SortOrder     = groupDto.SortOrder;
                group.PropertyTypes = new PropertyTypeCollection(MemberType.IsPublishingConst);

                //Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded
                var localGroupDto = groupDto;
                var typeDtos      = dto.PropertyTypes.Where(x => x.Id.HasValue && x.Id > 0 && x.PropertyTypeGroupId.HasValue && x.PropertyTypeGroupId.Value == localGroupDto.Id.Value);
                foreach (var typeDto in typeDtos)
                {
                    //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType
                    memberType.MemberTypePropertyTypes.Add(typeDto.Alias,
                                                           new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit, typeDto.IsSensitive));

                    var tempGroupDto = groupDto;

                    //ensures that any built-in membership properties have their correct dbtype assigned no matter
                    //what the underlying data type is
                    var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty(
                        typeDto.Alias,
                        typeDto.DbType.EnumParse <ValueStorageType>(true),
                        standardProps);

                    var propertyType = new PropertyType(
                        typeDto.PropertyEditorAlias,
                        propDbType.Result,
                        //This flag tells the property type that it has an explicit dbtype and that it cannot be changed
                        // which is what we want for the built-in properties.
                        propDbType.Success,
                        typeDto.Alias)
                    {
                        DataTypeId       = typeDto.DataTypeId,
                        Description      = typeDto.Description,
                        Id               = typeDto.Id.Value,
                        Name             = typeDto.Name,
                        Mandatory        = typeDto.Mandatory,
                        SortOrder        = typeDto.SortOrder,
                        ValidationRegExp = typeDto.ValidationRegExp,
                        PropertyGroupId  = new Lazy <int>(() => tempGroupDto.Id.Value),
                        CreateDate       = memberType.CreateDate,
                        UpdateDate       = memberType.UpdateDate,
                        Key              = typeDto.UniqueId
                    };

                    // reset dirty initial properties (U4-1946)
                    propertyType.ResetDirtyProperties(false);
                    group.PropertyTypes.Add(propertyType);
                }

                // reset dirty initial properties (U4-1946)
                group.ResetDirtyProperties(false);
                propertyGroups.Add(group);
            }

            return(propertyGroups);
        }
        public static IMemberType BuildEntity(MemberTypeReadOnlyDto dto, out bool needsSaving)
        {
            var standardPropertyTypes = Constants.Conventions.Member.GetStandardPropertyTypeStubs();

            needsSaving = false;

            var memberType = new MemberType(dto.ParentId);

            try
            {
                memberType.DisableChangeTracking();

                memberType.Alias               = dto.Alias;
                memberType.AllowedAsRoot       = dto.AllowAtRoot;
                memberType.CreateDate          = dto.CreateDate;
                memberType.CreatorId           = dto.UserId.HasValue ? dto.UserId.Value : 0;
                memberType.Description         = dto.Description;
                memberType.Icon                = dto.Icon;
                memberType.Id                  = dto.NodeId;
                memberType.IsContainer         = dto.IsContainer;
                memberType.Key                 = dto.UniqueId.Value;
                memberType.Level               = dto.Level;
                memberType.Name                = dto.Text;
                memberType.Path                = dto.Path;
                memberType.SortOrder           = dto.SortOrder;
                memberType.Thumbnail           = dto.Thumbnail;
                memberType.Trashed             = dto.Trashed;
                memberType.UpdateDate          = dto.CreateDate;
                memberType.AllowedContentTypes = Enumerable.Empty <ContentTypeSort>();

                var propertyTypeGroupCollection = GetPropertyTypeGroupCollection(dto, memberType, standardPropertyTypes);
                memberType.PropertyGroups = propertyTypeGroupCollection;

                var propertyTypes = GetPropertyTypes(dto, memberType, standardPropertyTypes);

                //By Convention we add 9 stnd PropertyTypes - This is only here to support loading of types that didn't have these conventions before.
                foreach (var standardPropertyType in standardPropertyTypes)
                {
                    if (dto.PropertyTypes.Any(x => x.Alias.Equals(standardPropertyType.Key)))
                    {
                        continue;
                    }

                    // beware!
                    // means that we can return a memberType "from database" that has some property types
                    // that do *not* come from the database and therefore are incomplete eg have no key,
                    // no id, no dataTypeDefinitionId - ouch! - better notify caller of the situation
                    needsSaving = true;

                    //Add the standard PropertyType to the current list
                    propertyTypes.Add(standardPropertyType.Value);

                    //Internal dictionary for adding "MemberCanEdit", "VisibleOnProfile", "IsSensitive" properties to each PropertyType
                    memberType.MemberTypePropertyTypes.Add(standardPropertyType.Key,
                                                           new MemberTypePropertyProfileAccess(false, false, false));
                }
                memberType.NoGroupPropertyTypes = propertyTypes;

                return(memberType);
            }
            finally
            {
                memberType.EnableChangeTracking();
            }
        }
예제 #7
0
        private PropertyGroupCollection GetPropertyTypeGroupCollection(MemberTypeReadOnlyDto dto, MemberType memberType, Dictionary <string, PropertyType> standardProps)
        {
            var propertyGroups = new PropertyGroupCollection();

            foreach (var groupDto in dto.PropertyTypeGroups.Where(x => x.Id.HasValue))
            {
                var group = new PropertyGroup();

                //Only assign an Id if the PropertyGroup belongs to this ContentType
                if (groupDto.ContentTypeNodeId == memberType.Id)
                {
                    group.Id = groupDto.Id.Value;

                    if (groupDto.ParentGroupId.HasValue)
                    {
                        group.ParentId = groupDto.ParentGroupId.Value;
                    }
                }
                else
                {
                    //If the PropertyGroup is inherited, we add a reference to the group as a Parent.
                    group.ParentId = groupDto.Id;
                }

                group.Name          = groupDto.Text;
                group.SortOrder     = groupDto.SortOrder;
                group.PropertyTypes = new PropertyTypeCollection();

                //Because we are likely to have a group with no PropertyTypes we need to ensure that these are excluded
                var localGroupDto = groupDto;
                var typeDtos      = dto.PropertyTypes.Where(x => x.Id.HasValue && x.Id > 0 && x.PropertyTypeGroupId.HasValue && x.PropertyTypeGroupId.Value == localGroupDto.Id.Value);
                foreach (var typeDto in typeDtos)
                {
                    //Internal dictionary for adding "MemberCanEdit" and "VisibleOnProfile" properties to each PropertyType
                    memberType.MemberTypePropertyTypes.Add(typeDto.Alias,
                                                           new MemberTypePropertyProfileAccess(typeDto.ViewOnProfile, typeDto.CanEdit));

                    var tempGroupDto = groupDto;

                    //ensures that any built-in membership properties have their correct dbtype assigned no matter
                    //what the underlying data type is
                    var propDbType = MemberTypeRepository.GetDbTypeForBuiltInProperty(
                        typeDto.Alias,
                        typeDto.DbType.EnumParse <DataTypeDatabaseType>(true),
                        standardProps);

                    var propertyType = new PropertyType(
                        typeDto.PropertyEditorAlias,
                        propDbType.Result,
                        //This flag tells the property type that it has an explicit dbtype and that it cannot be changed
                        // which is what we want for the built-in properties.
                        propDbType.Success,
                        typeDto.Alias)
                    {
                        DataTypeDefinitionId = typeDto.DataTypeId,
                        Description          = typeDto.Description,
                        Id               = typeDto.Id.Value,
                        Name             = typeDto.Name,
                        Mandatory        = typeDto.Mandatory,
                        SortOrder        = typeDto.SortOrder,
                        ValidationRegExp = typeDto.ValidationRegExp,
                        PropertyGroupId  = new Lazy <int>(() => tempGroupDto.Id.Value),
                        CreateDate       = memberType.CreateDate,
                        UpdateDate       = memberType.UpdateDate
                    };
                    //on initial construction we don't want to have dirty properties tracked
                    // http://issues.umbraco.org/issue/U4-1946
                    propertyType.ResetDirtyProperties(false);
                    group.PropertyTypes.Add(propertyType);
                }
                //on initial construction we don't want to have dirty properties tracked
                // http://issues.umbraco.org/issue/U4-1946
                group.ResetDirtyProperties(false);
                propertyGroups.Add(group);
            }

            return(propertyGroups);
        }