public TEntity ParseItemUsingTemplatePath <TEntity>(Item item, string templatePath)
            where TEntity : ISitecoreDomainEntity
        {
            IMap map = MapFinder.FindMap(templatePath);

            return((TEntity)m_resolver.ResolveEntity(item, map));
        }
        public static string GetTemplatePath <TEntity>()
            where TEntity : ISitecoreDomainEntity
        {
            Map <TEntity> map = MapFinder.FindMap <TEntity>();

            return(map.TemplatePath);
        }
        public void SaveItem <TEntity>(Item item, TEntity entity) where TEntity : ISitecoreDomainEntity
        {
            Map <TEntity> map = MapFinder.FindMap <TEntity>();

            using (new SecurityDisabler())
            {
                SaveItem(item, map, entity);
            }
        }
Beispiel #4
0
        public TEntity Update <TEntity>(TEntity entity) where TEntity : class, ISitecoreDomainEntity
        {
            var map = MapFinder.FindMap <TEntity>();

            using (new SecurityDisabler())
            {
                var item = MasterDatabase.GetItem(new ID(entity.Id));

                return(SaveItem(item, map, entity));
            }
        }
Beispiel #5
0
        public TEntity Create <TEntity>(string contentPath, TEntity entity) where TEntity : class, ISitecoreDomainEntity
        {
            var map          = MapFinder.FindMap <TEntity>();
            var templateItem = MasterDatabase.GetTemplate(map.TemplatePath);

            using (new SecurityDisabler())
            {
                var newItem = MasterDatabase.CreateItemPath(contentPath, templateItem);

                return(SaveItem(newItem, map, entity));
            }
        }
        public TEntity ParseItemUsingInferredTemplatePath <TEntity>(Item item, MapNotFoundBehaviour mapNotFoundBehaviour)
            where TEntity : ISitecoreDomainEntity
        {
            string templatePath = item.Template.FullName;
            IMap   map          = MapFinder.FindMap(templatePath);

            if (map == null && mapNotFoundBehaviour == MapNotFoundBehaviour.ReturnNullEntity)
            {
                return(default(TEntity));
            }
            return((TEntity)m_resolver.ResolveEntity(item, map));
        }
        public TEntity ParseItem <TEntity>(Item item)
            where TEntity : ISitecoreDomainEntity
        {
            Map <TEntity> map = MapFinder.FindMap <TEntity>();

            if (map == null)
            {
                return(default(TEntity));
            }

            return((TEntity)ParseItem(item, map));
        }
        public void CreateItem <TEntity>(string itemPath, TEntity entity) where TEntity : ISitecoreDomainEntity
        {
            Map <TEntity> map = MapFinder.FindMap <TEntity>();

            TemplateItem templateItem = GetTemplateItem(map.TemplatePath);

            using (new SecurityDisabler())
            {
                Item newItem = MasterDatabase.CreateItemPath(itemPath, templateItem);

                SaveItem(newItem, map, entity);
            }
        }
        public ISitecoreDomainEntity GetEntityOfType(Type entityType, Guid id)
        {
            Item item = GetItem(id);

            if (item != null)
            {
                IMap map = MapFinder.FindMap(entityType);
                if (map != null)
                {
                    return(m_resolver.ResolveEntity(item, map));
                }
            }

            return(null);
        }
        public void ProcessEntityChildren <TParent, TChild>(TParent entity, Action <TParent, TChild> actionOnChild)
            where TChild : ISitecoreDomainEntity
            where TParent : ISitecoreDomainEntity
        {
            Item item = GetItem(entity.Id);

            Map <TChild> map = MapFinder.FindMap <TChild>();

            if (map != null && item.HasChildren)
            {
                var    domainEntityRepository = new DomainEntityRepository();
                Guid[] childIds = Array.ConvertAll(item.Children.ToArray(), x => x.ID.Guid);
                IList <ISitecoreDomainEntity> childrenOfType = domainEntityRepository.GetEntities(childIds, map);
                foreach (ISitecoreDomainEntity childOfType in childrenOfType)
                {
                    actionOnChild(entity, (TChild)childOfType);
                }
            }
        }
        public static void UpdateProperty <TEntity, TProperty>(TEntity entity, Expression <Func <TEntity, TProperty> > propertyExpression) where TEntity : ISitecoreDomainEntity
        {
            Guard.ParameterNotNull(entity);
            Guard.ParameterNotNull(propertyExpression);

            IMap   entityMap    = MapFinder.FindMap <TEntity>() as IMap;
            string propertyName = propertyExpression.GetPropertyName();

            Logger.LogDebugMessage(String.Format("Updating property '{0}' of '{1}' for item {2}", propertyName, typeof(TEntity), entity.Id));

            MapEntry mapEntry = entityMap.Mappings.First(mapping => mapping.MappedProperty.Name == propertyName);


            using (new SecurityDisabler())
            {
                Item item = GetItem(entity.Id);

                item.Editing.BeginEdit();
                PropertyInfo mappedProperty = mapEntry.MappedProperty;
                object       resolvedValue  = DomainEntityPropertyResolver.ResolveItemFieldValue(mappedProperty, mappedProperty.GetValue(entity, null));
                item.Fields[mapEntry.MappedTo].Value = resolvedValue.ToString();
                item.Editing.EndEdit();
            }
        }
Beispiel #12
0
        public TEntity Read <TEntity>(Item item) where TEntity : class, ISitecoreDomainEntity
        {
            var map = MapFinder.FindMap <TEntity>();

            return((TEntity)m_resolver.ResolveEntity(item, map));
        }