Ejemplo n.º 1
0
        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();
                }
            }
        }