Exemplo n.º 1
0
 public GetChildWebCategoriesRequest(GetChildWebCategoriesRequest request)
 {
     this.WebID                 = request.WebID;
     this.TopCategoryID         = request.TopCategoryID;
     this.GetAllChildCategories = request.GetAllChildCategories;
     this.NestedType            = request.NestedType;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets web categories for the specified parentCategoryID
        /// </summary>
        /// <param name="request"></param>
        /// <param name="categoryList">(DO NOT USE)Internal variable used to pass master list of categories for recursive calls.  </param>
        /// <returns></returns>
        public static List <WebCategory> GetChildWebCategories(GetChildWebCategoriesRequest request, List <WebCategory> categoryList = null)
        {
            // get all categories
            var allCategories = categoryList ?? GetAllWebCategories(request.WebID);
            // get the children
            var webCategories = allCategories
                                .Where(c => c.ParentID == request.TopCategoryID)
                                // adds sort order upon getting the initial list of child categories.
                                // If sorting at any point after this, sort order is not guaranteed across parent/child
                                .OrderBy(c => c.SortOrder)
                                .ToList();

            // if requesting all children: populate children recursively
            if (request.GetAllChildCategories)
            {
                // create a temp list for holding grandchildren
                var childCategories = new List <WebCategory>();

                // get the children of each child (grandchildren)
                foreach (var child in webCategories)
                {
                    // set up request to get grandchildren
                    var grandchildRequest = new GetChildWebCategoriesRequest(request);
                    grandchildRequest.TopCategoryID = child.WebCategoryID;
                    var grandchildren = ExigoDAL.GetChildWebCategories(grandchildRequest, allCategories);

                    // if flat list is requested: Add to a temporary list
                    if (request.NestedType == NestedType.UniLevel)
                    {
                        childCategories.AddRange(grandchildren);
                    }

                    // if nesting is requested: add grandchildren to the child's subcategories
                    if (request.NestedType == NestedType.Nested)
                    {
                        child.Subcategories = grandchildren;
                    }
                }

                // if flat list is requested: add temp list of grandchildren to our original list.
                if (request.NestedType == NestedType.UniLevel)
                {
                    webCategories.AddRange(childCategories);
                }
            }

            // return children
            return(webCategories);
        }