Exemple #1
0
        /// <summary>
        /// Moves a PropertyType to a specified PropertyGroup
        /// </summary>
        /// <param name="propertyTypeAlias">Alias of the PropertyType to move</param>
        /// <param name="propertyGroupName">Name of the PropertyGroup to move the PropertyType to</param>
        /// <returns></returns>
        /// <remarks>If <paramref name="propertyGroupName"/> is null then the property is moved back to
        /// "generic properties" ie does not have a tab anymore.</remarks>
        public bool MovePropertyType(string propertyTypeAlias, string propertyGroupName)
        {
            // note: not dealing with alias casing at all here?

            // get property, ensure it exists
            var propertyType = PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);

            if (propertyType == null)
            {
                return(false);
            }

            // get new group, if required, and ensure it exists
            var newPropertyGroup = propertyGroupName == null
                ? null
                : PropertyGroups.FirstOrDefault(x => x.Name == propertyGroupName);

            if (propertyGroupName != null && newPropertyGroup == null)
            {
                return(false);
            }

            // get old group
            var oldPropertyGroup = PropertyGroups.FirstOrDefault(x =>
                                                                 x.PropertyTypes.Any(y => y.Alias == propertyTypeAlias));

            // set new group
            propertyType.PropertyGroupId = newPropertyGroup == null ? null : new Lazy <int>(() => newPropertyGroup.Id, false);

            // remove from old group, if any - add to new group, if any
            if (oldPropertyGroup != null)
            {
                oldPropertyGroup.PropertyTypes.RemoveItem(propertyTypeAlias);
            }
            if (newPropertyGroup != null)
            {
                newPropertyGroup.PropertyTypes.Add(propertyType);
            }

            return(true);
        }
Exemple #2
0
        public PropertyType EnsurePropertyType(string name, DataType dataType)
        {
            if (_editor == null)
            {
                _editor = new SchemaEditor();
            }

            var existing = PropertyTypes.FirstOrDefault(x => x.Name == name);

            if (existing != null)
            {
                if (existing.DataType != dataType)
                {
                    throw new ApplicationException($"DataType mismatch {existing.DataType} <-> {dataType}. PropertyType name: {name}, ");
                }
                return(existing);
            }
            var pt = _editor.CreatePropertyType(name, dataType);

            PropertyTypes.Add(pt);
            return(pt);
        }