Exemplo n.º 1
0
 public T Handel <T>(KeyValuePair <string, string> attribute, T obj) where T : IReflectionBase, new()
 {
     if (Type.GetType(attribute.Key)?.GetInterface(nameof(IReflectionBase)) != null)
     {
         var type = Type.GetType(attribute.Key);
         var attr = _reflectionService.GetAllAttribute <IReflectionBase>(type);
     }
     else
     {
         var parentItem = _sitecoreService.GetItemById(new GetItemOptions.GetItemByIdOptions {
             Id = Guid.Parse(_customContext.CurrentDatasourceId)
         });
         var templateID = (((IAttributeBase)typeof(T).GetProperty(attribute.Key).GetCustomAttributes(typeof(IAttributeBase), false).First()).Param);
         var item       = parentItem.GetChildren().Where(i => i.TemplateID == ID.Parse(templateID)).FirstOrDefault();
         if (item == null)
         {
             return(obj);
         }
         else
         {
             var commaSeparatedValue = item.Fields[attribute.Key].Value.Split(',').ToList();
             return((T)_reflectionService.FillCommaSeparated(commaSeparatedValue, obj, attribute.Key));
         }
     }
     return(obj);
 }
Exemplo n.º 2
0
        public Expression <Func <SearchResultItem, bool> > Query <T>(SearchSettings settings = null) where T : SearchResultItem
        {
            var itemPath = _sitecoreServices.GetItemById(new GetItemByIdOptions {
                Id = Guid.Parse(settings.Scopes.FirstOrDefault())
            }).Paths.FullPath;

            var rootPredicates = PredicateBuilder.False <SearchResultItem>();

            rootPredicates = rootPredicates.Or(i => i.Path.StartsWith(itemPath));
            return(rootPredicates);
        }
        public T Handel <T>(KeyValuePair <string, string> attribute, T obj) where T : IReflectionBase, new()
        {
            if (Type.GetType(attribute.Key)?.GetInterface(nameof(IReflectionBase)) != null)
            {
                var type = Type.GetType(attribute.Key);
                var attr = _reflectionService.GetAllAttribute <IReflectionBase>(type);
            }
            else
            {
                var parentItem = _sitecoreService.GetItemById(new GetItemOptions.GetItemByIdOptions {
                    Id = Guid.Parse(_customContext.CurrentDatasourceId)
                });
                var filedName          = (((IAttributeBase)typeof(T).GetProperty(attribute.Key).GetCustomAttributes(typeof(IAttributeBase), false).First()).Param);
                var parentTemplateID   = (((IAttributeBase)typeof(T).GetProperty(attribute.Key).GetCustomAttributes(typeof(IAttributeBase), false).First()).ParentTemplateID);
                var childrenTemplateID = (((IAttributeBase)typeof(T).GetProperty(attribute.Key).GetCustomAttributes(typeof(IAttributeBase), false).First()).ChildrenTemplateID);
                var items = parentItem.GetChildren().Where(i => i.TemplateID == ID.Parse(parentTemplateID)).FirstOrDefault();
                if (items == null)
                {
                    return(obj);
                }
                else
                {
                    var levelTwo = !string.IsNullOrEmpty(childrenTemplateID) ? items.GetChildren().Where(i => i.TemplateID == ID.Parse(childrenTemplateID)) : items.GetChildren();

                    if (items.Name != "Facets")
                    {
                        Dictionary <string, string> list = new Dictionary <string, string>();
                        foreach (var item in levelTwo)
                        {
                            list.Add(item.TemplateID.ToString(), item.Fields[filedName].Value);
                        }
                        return((T)_reflectionService.FillChildrens(attribute.Key, list, obj));
                    }
                    else
                    {
                        return((T)_reflectionService.FillChildrens(attribute.Key, levelTwo.Select(i => i.Fields[filedName].Value).ToList(), obj));
                    }
                }
            }
            return(obj);
        }