void LoadCategories() { MongoClient mclient = new MongoClient(GlobalVariables.mongolabConection); var db = mclient.GetDatabase(GlobalVariables.mongoDatabase); var collection = db.GetCollection<CategoriesCollection>("Categories"); //inputValue = "ev"; // var filter = Builders<IndividualData>.Filter.Eq("id", id); collection.Find(_ => true).ForEachAsync(d => { CategoryElements categoryElement = new CategoryElements(); //Response.Write(d._id.ToString() + "<p> --"); categoryElement._id = d._id.ToString(); categoryElement.parentId = d.parentCategories[0]["id"].ToString(); if(d.parentCategories != null) categoryElement.parent_id = d.parentCategories[0]["_id"].ToString(); // Response.Write(categoryElement.parent_id + "<p> --"); categoryElement.categoryName = d.categoryName; categoryElement.parentName = d.parentCategories[0]["parentName"].ToString(); categoryMap.Add(categoryElement); }).Wait(); }
int SetHierarhicalPosition(CategoryElements curentCategory, int curentPosition) { curentCategory.hierarchicalPosition = curentPosition; int j = 0; foreach (CategoryElements category in categoryMap) { if (category == null) break; if (category.parentName == curentCategory.categoryName) { SetHierarhicalPosition(category, curentPosition + 1); } j++; // Response.Write(tag.tagName + " " + tag.parentName + "<br />"); } return 0; }
int PopulateTreeView(CategoryElements parentCategory, int curentPosition, TreeNode parentNode) { // parentTag.hierarchicalPosition = curentPosition; int j = 0; foreach (CategoryElements category in categoryMap) { if (category.parentName == parentCategory.categoryName) { TreeNode curentNode = new TreeNode(); curentNode.Text = category.categoryName; curentNode.NavigateUrl = "CategoriesMap.aspx?category=" + category.categoryName; curentNode.Collapse(); parentNode.ChildNodes.Add(curentNode); PopulateTreeView(category, curentPosition + 1, curentNode); } j++; // Response.Write(tag.tagName + " " + tag.parentName + "<br />"); } return 0; }