/// <summary> /// Gets the children. /// </summary> /// <param name="id">The identifier.</param> /// <param name="db">The database.</param> /// <returns> /// Children list /// </returns> public ItemCommanderResponse GetChildren(string id, string db) { this.SetDatabase(db); var itemCommanderResponse = new ItemCommanderResponse(); var sitecoreItem = this.database.GetItem(new Sitecore.Data.ID(id)); itemCommanderResponse.CurrentPath = sitecoreItem.Paths.FullPath; itemCommanderResponse.CurrentId = id; itemCommanderResponse.ParentId = sitecoreItem.ParentID.ToString(); itemCommanderResponse.Children = sitecoreItem.Children.Select(t => new ItemResponse { Name = t.Name, Id = t.ID.ToString(), Language = t.Language.ToString(), Path = t.Paths.FullPath, TemplateName = t.TemplateName, Fields = new List <FieldResponse>(), HasChildren = t.HasChildren, LastModified = t.Statistics.Updated, Created = t.Statistics.Created, Icon = GetIcon(t), IsLocked = t.Locking.IsLocked(), IsHidden = t["__Hidden"] == "1" }).ToList(); return(itemCommanderResponse); }
/// <summary> /// Searches the specified keyword. /// </summary> /// <param name="keyword">The keyword.</param> /// <param name="db">The database.</param> /// <returns> /// Search result by keyword /// </returns> public ItemCommanderResponse Search(string keyword, string db) { this.SetDatabase(db); var itemCommanderResponse = new ItemCommanderResponse(); if (keyword.StartsWith("/")) { itemCommanderResponse.Children = this.database.SelectItems(keyword).Select(t => new ItemResponse { Name = t.Name, Id = t.ID.ToString(), Language = t.Language.ToString(), Path = t.Paths.FullPath, TemplateName = t.TemplateName, Fields = new List <FieldResponse>(), HasChildren = t.HasChildren, LastModified = t.Statistics.Updated, Created = t.Statistics.Created, Icon = GetIcon(t) }).ToList(); itemCommanderResponse.CurrentId = ""; } else { using (var searchContext = this.GetSearchIndex().CreateSearchContext()) { var queryable = searchContext.GetQueryable <ItemCommanderSearchResult>(); var predicate = PredicateBuilder.True <ItemCommanderSearchResult>(); var subPredicate = PredicateBuilder.True <ItemCommanderSearchResult>(); predicate = predicate.And(t => t.Path.StartsWith("/sitecore/content")); predicate = predicate.And(t => t.IsLatestVersion == true); predicate = predicate.And(t => t.Language == "en"); subPredicate = subPredicate.Or(t => t.Name.Contains(keyword)); subPredicate = subPredicate.Or(t => t.Content.Contains(keyword)); predicate = predicate.And(subPredicate); queryable = queryable.Filter(predicate); var results = queryable.GetResults().Where(t => t.Document.GetItem() != null); itemCommanderResponse.Children = results.Select(t => new ItemResponse { Name = t.Document.Name, Id = t.Document.ItemId.ToString(), Language = t.Document.Language.ToString(), Path = t.Document.Path, TemplateName = t.Document.TemplateName, Fields = new List <FieldResponse>(), HasChildren = t.Document.GetItem().HasChildren, LastModified = t.Document.Updated, Created = t.Document.CreatedDate, Icon = GetIcon(t.Document.GetItem()) }).ToList(); itemCommanderResponse.CurrentId = ""; // it should be empty string for the frontend } } return(itemCommanderResponse); }