예제 #1
0
        /// <summary>
        /// Gets all children nodes from a given node id.
        /// </summary>
        /// <param name="parentId">Parent node id of all children to get</param>
        /// <param name="deepGet">if set to <c>true</c> method will return children's children (complete tree).</param>
        /// <returns></returns>
        public static IEnumerable <DocumentTypeBase> GetChildren(int parentId, bool deepGet)
        {
            Node parentNode = uQuery.GetNode(parentId);

            if (parentNode.Id == parentId) // check if it is loaded correctly
            {
                IEnumerable <Node> childNodes = null;
                if (deepGet)
                {
                    childNodes = parentNode.GetDescendantNodes();
                }
                else
                {
                    childNodes = parentNode.GetChildNodes();
                }

                if (childNodes != null)
                {
                    foreach (Node childNode in childNodes)
                    {
                        // Check if this childNode is not deleted
                        if (!ContentHelper.IsInRecycleBin(childNode.Path))
                        {
                            var d = DocumentTypeResolver.Instance.GetTyped <DocumentTypeBase>(childNode);
                            if (d != null)
                            {
                                yield return(d);
                            }
                        }
                    }
                }
            }
        }
예제 #2
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);
                    }
                }
            }
        }