private static void SwapAndReNumberSortOrder(Category source, Category dest) { List <Category> allCats = CategoryCollection.GetCategoryList(source.StoreId.Value, true); int sourceIndex = allCats.FindIndex(x => x.Id == source.Id); int destIndex = allCats.FindIndex(x => x.Id == dest.Id); if (sourceIndex > -1 && destIndex > -1) { var swap = source; allCats[sourceIndex] = allCats[destIndex]; allCats[destIndex] = swap; for (short i = 0; i < allCats.Count; i++) { var c = new Category(); if (c.LoadByPrimaryKey(allCats[i].Id.Value)) { c.SortOrder = i; c.Save(); } //allCats[i].SortOrder = i; //allCats[i].Save(); } } }
public List <Category> GetCategories(bool includeHiddenCategories) { // This is correct, but there's a bug in ES that doesn't honor the DNN Object Qualifier for M2M collections :( //List<Category> categories = this.UpToCategoryCollection; //if (!includeHiddenCategories) //{ // categories.RemoveAll(c => !c.IsDisplayed.GetValueOrDefault()); //} //return categories; //SELECT //c.* //FROM DNNspot_Store_Category c //INNER JOIN DNNspot_Store_ProductCategory pc ON pc.CategoryId = c.Id //WHERE pc.ProductId = 21 CategoryQuery c = new CategoryQuery("c"); ProductCategoryQuery pc = new ProductCategoryQuery("pc"); c.Select(c).InnerJoin(pc).On(c.Id == pc.CategoryId); c.Where(pc.ProductId == this.Id.Value); CategoryCollection collection = new CategoryCollection(); collection.Load(c); return(collection.ToList()); }
public static List <Category> GetTopLevelCategories(int storeId, bool includeHidden) { CategoryQuery qry = new CategoryQuery(); qry.Where(qry.StoreId == storeId); qry.Where(qry.ParentId.IsNull()); if (!includeHidden) { qry.Where(qry.IsDisplayed == true); } qry.OrderBy(qry.SortOrder.Ascending, qry.Name.Ascending); CategoryCollection rootCategories = new CategoryCollection(); rootCategories.Load(qry); List <Category> catList = new List <Category>(rootCategories.Count); foreach (var c in rootCategories) { catList.Add(c); } //return rootCategories; return(catList); }
private static void AddChildCategoriesToList(Category parent, ref List <Category> list, bool includeHidden) { CategoryCollection childCats = parent.GetChildCategoriesInSortedOrder(includeHidden); foreach (Category child in childCats) { list.Add(child); AddChildCategoriesToList(child, ref list, includeHidden); } }
//public static List<CategoryNode> GetCategoryNodeTree() //{ // List<CategoryNode> cats = new List<CategoryNode>(); // cats.AddRange(GetTopLevelCategories().ConvertAll(c => new CategoryNode() { Category = c })); // foreach (CategoryNode parentInfo in cats) // { // AddChildCategoryNodesRecursive(parentInfo); // } // return cats; //} //private static void AddChildCategoryNodesRecursive(CategoryNode parentInfo) //{ // parentInfo.SubCategories = ((List<Category>)parentInfo.Category.GetChildCategoriesInSortedOrder()).ConvertAll(c => new CategoryNode() { Category = c }); // foreach (CategoryNode child in parentInfo.SubCategories) // { // AddChildCategoryNodesRecursive(child); // } //} internal static void UpdateAllNestingLevels() { CategoryCollection allCategories = new CategoryCollection(); allCategories.LoadAll(); foreach (Category cat in allCategories) { cat.NestingLevel = cat.GetNestingLevel(); } allCategories.Save(); }
public CategoryCollection GetChildCategoriesInSortedOrder(bool includeHidden) { //SortChildCategories(); //return this.CategoryCollectionByParentId; CategoryQuery q = new CategoryQuery(); q.Where(q.ParentId == this.Id.Value); if (!includeHidden) { q.Where(q.IsDisplayed == true); } q.OrderBy(q.SortOrder.Ascending, q.Name.Ascending); CategoryCollection collection = new CategoryCollection(); collection.Load(q); return(collection); }
public static void SetSortOrderByListPosition(List <int> categoryIdsInSortOrder) { CategoryQuery q = new CategoryQuery(); q.Where(q.Id.In(categoryIdsInSortOrder.ToArray())); CategoryCollection collection = new CategoryCollection(); if (collection.Load(q)) { for (short i = 0; i < categoryIdsInSortOrder.Count; i++) { Category c = collection.FindByPrimaryKey(categoryIdsInSortOrder[i]); if (c != null) { c.SortOrder = i; } } collection.Save(); } }