Example #1
0
        public void SetItemPropertyMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var idProperty = propertyMeta as IdPropertyMeta <TModel>;

            if (idProperty == null)
            {
                return;
            }

            ItemPropertyMappingType mappingType;

            if (!Enum.TryParse(idProperty.MappingName, true, out mappingType))
            {
                return;
            }

            switch (mappingType)
            {
            case ItemPropertyMappingType.ItemId:
                idProperty.AssignValueToModelProperty(model, item.ID);
                break;

            case ItemPropertyMappingType.TemplateId:
                idProperty.AssignValueToModelProperty(model, item.TemplateID);
                break;
            }
        }
Example #2
0
        public void HandleMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper)
        {
            var childMapPropertyMeta = propertyMeta as IChildMappingPropertyMeta;

            if (childMapPropertyMeta == null || model.GetType().GetProperty(propertyMeta.PropertyName).Equals(null))
            {
                return;
            }

            var property = model.GetType().GetProperty(propertyMeta.PropertyName);
            var listType = property.PropertyType.GetGenericArguments()[0];

            var genericList = typeof(List <>).MakeGenericType(listType);
            var collection  = Activator.CreateInstance(genericList) as IList;

            if (collection == null)
            {
                return;
            }

            var parentItem = GetParentItemForChildCollection(item, childMapPropertyMeta);

            if (parentItem != null)
            {
                foreach (Item childItem in parentItem.Children)
                {
                    var childObject = Activator.CreateInstance(listType) as dynamic;
                    itemMapper.Map(childObject, childItem);
                    collection.Add(childObject);
                }
            }
            property.SetValue(model, collection);
        }
Example #3
0
        public void HandleMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper)
        {
            var listField = (MultilistField)item.Fields[propertyMeta.MappingName];

            if (listField == null)
            {
                return;
            }

            var listItems = listField.GetItems();

            var property = model.GetType().GetProperty(propertyMeta.PropertyName);

            var listType = property.PropertyType.GetGenericArguments()[0];

            var genericList = typeof(List <>).MakeGenericType(listType);
            var collection  = Activator.CreateInstance(genericList) as IList;

            if (collection == null)
            {
                return;
            }

            foreach (var linkedItem in listItems)
            {
                var childObject = Activator.CreateInstance(listType) as dynamic;
                itemMapper.Map(childObject, linkedItem);
                collection.Add(childObject);
            }
            property.SetValue(model, collection);
        }
Example #4
0
        public void HandleMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper)
        {
            var itemPropertyMappings = MappingUtil.GetItemPropertyMappers(cache);

            if (itemPropertyMappings.ContainsKey(propertyMeta.PropertyKey))
            {
                itemPropertyMappings[propertyMeta.PropertyKey].SetItemPropertyMapping(model, propertyMeta, item);
            }
        }
        public void SetRenderingParameterMappingMapping <TModel>(TModel model, IPropertyMeta propertyMeta, RenderingContext renderingContext)
        {
            var intProperty = propertyMeta as IntPropertyMeta <TModel>;

            if (intProperty == null)
            {
                return;
            }

            intProperty.AssignValueToModelProperty(model, renderingContext.Rendering.GetParameter(propertyMeta.MappingName, 0));
        }
        public void SetDictionaryFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var propertyMetaDictionaryString = propertyMeta as StringPropertyMeta <TModel>;

            if (propertyMetaDictionaryString == null)
            {
                return;
            }

            propertyMetaDictionaryString.AssignValueToModelProperty(model, Translate.Text(propertyMetaDictionaryString.MappingName));
        }
Example #7
0
        public void SetModelFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var stringProperty = propertyMeta as StringPropertyMeta <TModel>;

            if (stringProperty == null)
            {
                return;
            }

            stringProperty.AssignValueToModelProperty(model, Translate.Text(item[stringProperty.MappingName]));
        }
Example #8
0
        public void SetModelFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var linkFieldProperty = propertyMeta as LinkFieldRenderingStringPropertyMeta <TModel>;

            if (linkFieldProperty == null)
            {
                return;
            }

            linkFieldProperty.AssignValueToModelProperty(model, new LinkFieldRenderingString(item, linkFieldProperty.MappingName));
        }
Example #9
0
        public void SetModelFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var mediaFieldProperty = propertyMeta as MediaRenderingStringPropertyMeta <TModel>;

            if (mediaFieldProperty == null)
            {
                return;
            }

            mediaFieldProperty.AssignValueToModelProperty(model, new MediaRenderingString(item, mediaFieldProperty.MappingName));
        }
Example #10
0
        public void SetModelFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var intProperty = propertyMeta as IntPropertyMeta <TModel>;

            if (intProperty == null)
            {
                return;
            }

            intProperty.AssignValueToModelProperty(model, int.Parse(item[intProperty.MappingName]));
        }
Example #11
0
        public void SetModelFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var boolProperty = propertyMeta as BoolPropertyMeta <TModel>;

            if (boolProperty == null)
            {
                return;
            }

            boolProperty.AssignValueToModelProperty(model, item[boolProperty.MappingName].Equals("1", StringComparison.InvariantCultureIgnoreCase));
        }
Example #12
0
        public void SetModelFieldMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var doubleProperty = propertyMeta as DoublePropertyMeta <TModel>;

            if (doubleProperty == null)
            {
                return;
            }

            doubleProperty.AssignValueToModelProperty(model, double.Parse(item[doubleProperty.MappingName]));
        }
Example #13
0
        public void HandleMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper)
        {
            var itemFieldMappings = MappingUtil.GetFieldMappers(cache);

            if (item == null || item.Fields[propertyMeta.MappingName] == null)
            {
                return;
            }

            if (itemFieldMappings.ContainsKey(propertyMeta.PropertyKey))
            {
                itemFieldMappings[propertyMeta.PropertyKey].SetModelFieldMapping(model, propertyMeta, item);
            }
            else
            {
                HandleLinkedObjectMapping(model, item, propertyMeta, itemMapper);
            }
        }
        public void SetItemPropertyMapping <TModel>(TModel model, IPropertyMeta propertyMeta, Item item)
        {
            var stringProperty = propertyMeta as StringPropertyMeta <TModel>;

            if (stringProperty == null)
            {
                return;
            }

            ItemPropertyMappingType mappingType;

            if (!Enum.TryParse(stringProperty.MappingName, true, out mappingType))
            {
                return;
            }

            switch (mappingType)
            {
            case ItemPropertyMappingType.ItemId:
                stringProperty.AssignValueToModelProperty(model, item.ID.ToString());
                break;

            case ItemPropertyMappingType.ItemUrl:
                stringProperty.AssignValueToModelProperty(model, item.GetItemUrl());
                break;

            case ItemPropertyMappingType.TemplateId:
                stringProperty.AssignValueToModelProperty(model, item.TemplateID.ToString());
                break;

            case ItemPropertyMappingType.TemplateName:
                stringProperty.AssignValueToModelProperty(model, item.TemplateName);
                break;

            case ItemPropertyMappingType.ItemName:
                stringProperty.AssignValueToModelProperty(model, item.Name);
                break;

            case ItemPropertyMappingType.ItemPath:
                stringProperty.AssignValueToModelProperty(model, item.Paths.Path);
                break;
            }
        }
Example #15
0
        public void HandleMapping <TModel>(
            TModel model,
            Item item,
            IPropertyMeta propertyMeta,
            ICache cache,
            IItemMapper itemMapper)
        {
            var renderingParameterMappings = MappingUtil.GetRenderingParameterMappers(cache);
            var renderingContext           = RenderingContext.Current;

            if (renderingContext != null)
            {
                if (renderingParameterMappings.ContainsKey(propertyMeta.PropertyKey))
                {
                    renderingParameterMappings[propertyMeta.PropertyKey].SetRenderingParameterMappingMapping(
                        model,
                        propertyMeta,
                        renderingContext);
                }
            }
        }
Example #16
0
        private void HandleLinkedObjectMapping <TModel>(TModel model, Item item, IPropertyMeta propertyMeta, IItemMapper itemMapper)
        {
            Guid guid;

            if (!Guid.TryParse(item[propertyMeta.MappingName], out guid))
            {
                return;
            }

            var linkedItem = global::Sitecore.Context.Database.GetItem(new ID(guid));

            if (linkedItem == null)
            {
                return;
            }

            var property     = model.GetType().GetProperty(propertyMeta.PropertyName);
            var linkedObject = Activator.CreateInstance(property.PropertyType) as dynamic;

            itemMapper.Map(linkedObject, linkedItem);
            property.SetValue(model, linkedObject);
        }