public void GetCategoryListByParentID(Int64 parID) { try { OiiOHaatDCDataContext dbContext = DatabaseHelper.GetDataModelDataContext(); var catListByParentID = dbContext.SP_CategoryTree_GetSearchedCategoryOrAll(null, parID).ToList(); dbContext.Dispose(); foreach (var category in catListByParentID) { count = 0; CountCounter(category.ParentID); count = count - subCatCounter; string msg = "- "; string newSpaceMsg = string.Empty; //space for subcategory for (int spaceCount = 0; spaceCount < count; spaceCount++) { newSpaceMsg = msg + newSpaceMsg; } category.Description = newSpaceMsg + category.Name; if (categoryList.All(c => c.IID != category.IID)) { categoryList.Add(category); } GetCategoryListByParentID(category.IID); } } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
public List <SP_CategoryTree_GetSearchedCategoryOrAllResult> GetAllSearchedCategory(string catName) { try { OiiOHaatDCDataContext dbContext = DatabaseHelper.GetDataModelDataContext(); var catList = new List <SP_CategoryTree_GetSearchedCategoryOrAllResult>(); if (catName == " ") { catList = dbContext.SP_CategoryTree_GetSearchedCategoryOrAll(null, null).ToList(); } else { catList = dbContext.SP_CategoryTree_GetSearchedCategoryOrAll(catName, null).ToList(); //var catList1 = new List<SP_CategoryTree_GetSearchedCategoryOrAllResult>(); //catList1.AddRange(catList); //var catList2 = new List<SP_CategoryTree_GetSearchedCategoryOrAllResult>(); //catList2.AddRange(catList); //catList = null; //catList = new List<SP_CategoryTree_GetSearchedCategoryOrAllResult>(); //foreach (var category1 in catList1) //{ // foreach (var category2 in catList2) // { // if (category1.Name == category2.Name) // { // var cat = new SP_CategoryTree_GetSearchedCategoryOrAllResult(); // var category = GetCategoryByID(category2.ParentID != null ? Convert.ToInt64(category2.ParentID) : 0); // cat.IID = category.IID; // cat.ParentID = category.ParentID; // cat.Description = category.Description; // cat.Name = category.Name; // catList.Add(cat); // } // else // { // catList.Add(category2); // } // } //} } // dbContext.Dispose(); if (catList.Count > 0) { foreach (var categoryDb in catList) { count = 0; CountCounter(categoryDb.ParentID); subCatCounter = count; categoryDb.Description = categoryDb.Name; if (categoryList.All(c => c.IID != categoryDb.IID)) { categoryList.Add(categoryDb); } GetCategoryListByParentID(categoryDb.IID); } } return(categoryList.ToList()); } catch (Exception exception) { throw new Exception(exception.Message, exception); } }