public static IEnumerable <T> SiblingsOfType <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase { if (input.NodeDetails.PublishedContent == null || input.NodeDetails.PublishedContent.Parent == null || input.NodeDetails.PublishedContent.Parent.Children == null) { return(new List <T>()); } return(input.NodeDetails.PublishedContent.Parent.Children.Where(x => x != input).ContentOfType <T>()); }
public static bool IsAncestorOf <T>(this CodeFirstContentBase input, T comparator) where T : CodeFirstContentBase { var path = comparator.NodeDetails.PublishedContent?.Path.Split(',').Select(x => int.Parse(x)); try { return(path.Contains(input.NodeDetails.UmbracoId)); } catch (NullReferenceException) { throw new CodeFirstException("All code-first LINQ methods can only be used against published content. One or more of the node arguments was constructed from IContent"); } }
protected void MapModelToContent(IContentBase node, CodeFirstContentBase <T> model, ContentTypeRegistration registration, bool firstLevel = true) { if (firstLevel) { node.Name = model.NodeDetails.Name; node.SortOrder = model.NodeDetails.SortOrder; } foreach (var prop in registration.Properties) { var val = prop.Metadata.GetValue(model); if (val != null) { SetPropertyOnContent(node, prop, val); } } //Get and then set all the properties from any tabs var tabs = registration.Tabs; foreach (var tab in tabs) { var tabInstance = tab.PropertyOfParent.GetValue(model); if (tabInstance != null) { foreach (var prop in tab.Properties) { var val = prop.Metadata.GetValue(tabInstance); if (val != null) { SetPropertyOnContent(node, prop, val); } } } } foreach (var comp in registration.Compositions) { MapModelToContent(node, (CodeFirstContentBase <T>)comp.PropertyOfContainer.GetValue(model), comp, false); } }
public static string GetContextualAttributes(this CodeFirstContentBase input) { return(DataTypeUtils.GetHtmlTagContentFromContextualAttributes(input)); }
public static T NearestDescendant <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase { return((T)input.NodeDetails.PublishedContent.NearestDescendant <T>().ConvertToModel()); }
public static T SingleChild <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase { return((T)input.NodeDetails.PublishedContent.SingleChild <T>().ConvertToModel()); }
public static IEnumerable <T> AncestorsOfType <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase { return(input.NodeDetails.PublishedContent.Ancestors().ContentOfType <T>()); }
public static IEnumerable <T> ChildrenOfType <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase { return(input.NodeDetails.PublishedContent.Children.ContentOfType <T>()); }