Пример #1
0
        private static IPropertyType MapSaveProperty(PropertyTypeBasic sourceProperty,
                                                     IEnumerable <IPropertyType> destOrigProperties, MapperContext context)
        {
            IPropertyType destProperty;

            if (sourceProperty.Id > 0)
            {
                // updating an existing property
                // ensure it is still there, then map/update
                destProperty = destOrigProperties.FirstOrDefault(x => x.Id == sourceProperty.Id);
                if (destProperty != null)
                {
                    context.Map(sourceProperty, destProperty);
                    return(destProperty);
                }

                // force-clear the ID as it does not match anything
                sourceProperty.Id = 0;
            }

            // insert a new property, or update an existing property that has
            // been deleted in the meantime and we need to re-create
            // map/create
            destProperty = context.Map <IPropertyType>(sourceProperty);
            return(destProperty);
        }
Пример #2
0
        // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate
        // Umbraco.Code.MapAll -SupportsPublishing -Key -PropertyEditorAlias -ValueStorageType -Variations
        private static void Map(PropertyTypeBasic source, IPropertyType target, MapperContext context)
        {
            target.Name                    = source.Label;
            target.DataTypeId              = source.DataTypeId;
            target.DataTypeKey             = source.DataTypeKey;
            target.Mandatory               = source.Validation.Mandatory;
            target.MandatoryMessage        = source.Validation.MandatoryMessage;
            target.ValidationRegExp        = source.Validation.Pattern;
            target.ValidationRegExpMessage = source.Validation.PatternMessage;
            target.SetVariesBy(ContentVariation.Culture, source.AllowCultureVariant);
            target.SetVariesBy(ContentVariation.Segment, source.AllowSegmentVariant);

            if (source.Id > 0)
            {
                target.Id = source.Id;
            }

            if (source.GroupId > 0)
            {
                target.PropertyGroupId = new Lazy <int>(() => source.GroupId, false);
            }

            target.Alias       = source.Alias;
            target.Description = source.Description;
            target.SortOrder   = source.SortOrder;
            target.LabelOnTop  = source.LabelOnTop;
        }
    public void PropertyTypeBasic_To_PropertyTypeDisplay()
    {
        // TODO use builder
        var dataType = new DataType(Services.GetRequiredService <LabelPropertyEditor>(), _serializer)
        {
            Name = "TODO"
        };

        var basic = new PropertyTypeBasic
        {
            Id          = 33,
            SortOrder   = 1,
            Alias       = "prop1",
            Description = "property 1",
            DataTypeId  = dataType.Id,
            GroupId     = 222,
            Label       = "Prop 1",
            Validation  = new PropertyTypeValidation {
                Mandatory = true, Pattern = "xyz"
            }
        };

        var result = _sut.Map <PropertyTypeDisplay>(basic);

        Assert.AreEqual(basic.Id, result.Id);
        Assert.AreEqual(basic.SortOrder, result.SortOrder);
        Assert.AreEqual(basic.Alias, result.Alias);
        Assert.AreEqual(basic.Description, result.Description);
        Assert.AreEqual(basic.GroupId, result.GroupId);
        Assert.AreEqual(basic.Inherited, result.Inherited);
        Assert.AreEqual(basic.Label, result.Label);
        Assert.AreEqual(basic.Validation, result.Validation);
    }
Пример #4
0
 // Umbraco.Code.MapAll -Editor -View -Config -ContentTypeId -ContentTypeName -Locked
 private static void Map(PropertyTypeBasic source, PropertyTypeDisplay target, MapperContext context)
 {
     target.Alias = source.Alias;
     target.AllowCultureVariant = source.AllowCultureVariant;
     target.DataTypeId          = source.DataTypeId;
     target.Description         = source.Description;
     target.GroupId             = source.GroupId;
     target.Id         = source.Id;
     target.Inherited  = source.Inherited;
     target.Label      = source.Label;
     target.SortOrder  = source.SortOrder;
     target.Validation = source.Validation;
 }
    public void PropertyTypeBasic_To_PropertyType()
    {
        // TODO use builder
        var dataType = new DataType(Services.GetRequiredService <LabelPropertyEditor>(), _serializer)
        {
            Name = "TODO"
        };

        _dataTypeService.Save(dataType);

        var basic = new PropertyTypeBasic
        {
            Id          = 33,
            SortOrder   = 1,
            Alias       = "prop1",
            Description = "property 1",
            DataTypeId  = dataType.Id,
            GroupId     = 222,
            Label       = "Prop 1",
            Validation  = new PropertyTypeValidation
            {
                Mandatory        = true,
                MandatoryMessage = "Please enter a value",
                Pattern          = "xyz",
                PatternMessage   = "Please match the pattern"
            }
        };

        var result = _sut.Map <IPropertyType>(basic);

        Assert.AreEqual(basic.Id, result.Id);
        Assert.AreEqual(basic.SortOrder, result.SortOrder);
        Assert.AreEqual(basic.Alias, result.Alias);
        Assert.AreEqual(basic.Description, result.Description);
        Assert.AreEqual(basic.DataTypeId, result.DataTypeId);
        Assert.AreEqual(basic.Label, result.Name);
        Assert.AreEqual(basic.Validation.Mandatory, result.Mandatory);
        Assert.AreEqual(basic.Validation.MandatoryMessage, result.MandatoryMessage);
        Assert.AreEqual(basic.Validation.Pattern, result.ValidationRegExp);
        Assert.AreEqual(basic.Validation.PatternMessage, result.ValidationRegExpMessage);
        Assert.AreEqual(basic.LabelOnTop, result.LabelOnTop);
    }
        private ValidationResult ValidateProperty(PropertyTypeBasic property, int groupIndex, int propertyIndex)
        {
            //don't let them match any properties or methods in IPublishedContent
            //TODO: There are probably more!
            var reservedProperties = typeof(IPublishedContent).GetProperties().Select(x => x.Name).ToArray();
            var reservedMethods    = typeof(IPublishedContent).GetMethods().Select(x => x.Name).ToArray();

            var alias = property.Alias;

            if (reservedProperties.InvariantContains(alias) || reservedMethods.InvariantContains(alias))
            {
                return(new ValidationResult(
                           string.Format("The alias {0} is a reserved term and cannot be used", alias), new[]
                {
                    string.Format("Groups[{0}].Properties[{1}].Alias", groupIndex, propertyIndex)
                }));
            }

            return(null);
        }
Пример #7
0
        // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate
        // Umbraco.Code.MapAll -SupportsPublishing -Key -PropertyEditorAlias -ValueStorageType
        private static void Map(PropertyTypeBasic source, PropertyType target, MapperContext context)
        {
            target.Name             = source.Label;
            target.DataTypeId       = source.DataTypeId;
            target.Mandatory        = source.Validation.Mandatory;
            target.ValidationRegExp = source.Validation.Pattern;
            target.Variations       = source.AllowCultureVariant ? ContentVariation.Culture : ContentVariation.Nothing;

            if (source.Id > 0)
            {
                target.Id = source.Id;
            }

            if (source.GroupId > 0)
            {
                target.PropertyGroupId = new Lazy <int>(() => source.GroupId, false);
            }

            target.Alias       = source.Alias;
            target.Description = source.Description;
            target.SortOrder   = source.SortOrder;
        }