Beispiel #1
0
 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>());
 }
Beispiel #2
0
        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);
            }
        }
Beispiel #4
0
 public static string GetContextualAttributes(this CodeFirstContentBase input)
 {
     return(DataTypeUtils.GetHtmlTagContentFromContextualAttributes(input));
 }
Beispiel #5
0
 public static T NearestDescendant <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase
 {
     return((T)input.NodeDetails.PublishedContent.NearestDescendant <T>().ConvertToModel());
 }
Beispiel #6
0
 public static T SingleChild <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase
 {
     return((T)input.NodeDetails.PublishedContent.SingleChild <T>().ConvertToModel());
 }
Beispiel #7
0
 public static IEnumerable <T> AncestorsOfType <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase
 {
     return(input.NodeDetails.PublishedContent.Ancestors().ContentOfType <T>());
 }
Beispiel #8
0
 public static IEnumerable <T> ChildrenOfType <T>(this CodeFirstContentBase input) where T : CodeFirstContentBase
 {
     return(input.NodeDetails.PublishedContent.Children.ContentOfType <T>());
 }