public GenericContent GetContentByID(int nodeID) { int[] ids = { 0 }; ids[0] = nodeID; var content = Services.ContentService.GetByIds(ids); GenericContent valueToReturn = new GenericContent(); valueToReturn.id = content.FirstOrDefault().Id; valueToReturn.name = content.FirstOrDefault().Name; valueToReturn.ContentType = content.FirstOrDefault().ContentType.Alias; valueToReturn.CreateDate = content.FirstOrDefault().CreateDate; valueToReturn.CreatorID = content.FirstOrDefault().CreatorId; foreach(Umbraco.Core.Models.Property prop in content.FirstOrDefault().Properties) { valueToReturn.properties.Add(prop.Alias, prop.Value); } return valueToReturn; }
public GenericContent[] GetContentUnderNode(int nodeID) { int[] ids = { 0 }; ids[0] = nodeID; List<GenericContent> content = new List<GenericContent>(); var rootItems = Services.ContentService.GetByIds(ids); foreach (var item in rootItems) { GenericContent CurrentItem = new GenericContent(); CurrentItem.id = item.Id; CurrentItem.name = item.Name; CurrentItem.ContentType = item.ContentType.Alias; CurrentItem.CreateDate = item.CreateDate; CurrentItem.CreatorID = item.CreatorId; foreach (Umbraco.Core.Models.Property prop in item.Properties) { CurrentItem.properties.Add(prop.Alias, prop.Value); } content.Add(CurrentItem); content.AddRange(ListContentData(rootItems)); } return content.ToArray(); }
private IEnumerable<GenericContent> ListContentData(IEnumerable<IContent> rootItems) { List<GenericContent> ids = new List<GenericContent>(); foreach (var item in rootItems) { GenericContent CurrentItem = new GenericContent(); CurrentItem.id = rootItems.FirstOrDefault().Id; CurrentItem.name = rootItems.FirstOrDefault().Name; CurrentItem.ContentType = rootItems.FirstOrDefault().ContentType.Alias; CurrentItem.CreateDate = rootItems.FirstOrDefault().CreateDate; CurrentItem.CreatorID = rootItems.FirstOrDefault().CreatorId; foreach (Umbraco.Core.Models.Property prop in rootItems.FirstOrDefault().Properties) { CurrentItem.properties.Add(prop.Alias, prop.Value); } ids.Add(CurrentItem); if (Services.ContentService.HasChildren(item.Id)) foreach (IEnumerable<IContent> newItem in Services.ContentService.GetChildren(item.Id)) { // To learn about recursion one must first learn about recursion. ids.AddRange(ListContentData(newItem)); } } return ids; }