Ejemplo n.º 1
0
        /// <summary>
        /// Gets all children nodes of a given type from a given node id.
        /// </summary>
        /// <typeparam name="T">Strongly typed content item</typeparam>
        /// <param name="parentId">Parent node id of all children to get</param>
        /// <param name="deepGet">If true it does deep search for children in the whole content tree starting from node whose id is parentId)</param>
        public static IEnumerable <T> GetChildren <T>(int parentId, bool deepGet)
            where T : DocumentTypeBase, new()
        {
            Node parentNode = uQuery.GetNode(parentId);

            string docTypeAlias = DocumentTypeManager.GetDocumentTypeAlias(typeof(T));

            IEnumerable <Node> childNodes = null;

            if (deepGet)
            {
                childNodes = parentNode.GetDescendantNodes();
            }
            else
            {
                childNodes = parentNode.GetChildNodes();
            }

            foreach (Node childNode in childNodes)
            {
                // Check if this childNode is of a given document type and if not deleted
                if (docTypeAlias == childNode.NodeTypeAlias && !ContentHelper.IsInRecycleBin(childNode.Path))
                {
                    var d = ContentHelper.GetByNode <T>(childNode);
                    if (d != null)
                    {
                        yield return(d);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all ancestor nodes of a given type from a given node id.
        /// (parent's path back to root)
        /// </summary>
        /// <typeparam name="T">Strongly typed content item</typeparam>
        /// <param name="nodeId">Id of node for which to retrieve node ancestors</param>
        public static IEnumerable <T> GetAncestors <T>(int nodeId)
            where T : DocumentTypeBase, new()
        {
            Node parentNode = uQuery.GetNode(nodeId);

            string docTypeAlias = DocumentTypeManager.GetDocumentTypeAlias(typeof(T));

            IEnumerable <Node> ancestorNodes = parentNode.GetAncestorNodes();

            foreach (Node childNode in ancestorNodes)
            {
                // Check if this childNode is of a given document type and if not deleted
                if (docTypeAlias != childNode.NodeTypeAlias)
                {
                    continue;
                }

                var d = ContentHelper.GetByNode <T>(childNode);
                if (d != null)
                {
                    yield return(d);
                }
            }
        }