示例#1
0
        public static void MoveCategoryDown(int categoryId)
        {
            Category source = new Category();

            if (source.LoadByPrimaryKey(categoryId))
            {
                //SELECT TOP 1 *
                //FROM DNNspot_Store_Category WHERE StoreId = 1 AND ParentId IS NULL AND SortOrder >= 3 AND Id <> 33
                //ORDER BY SortOrder ASC
                CategoryQuery q = new CategoryQuery();
                q.es.Top = 1;
                q.Where(q.StoreId == source.StoreId);
                if (source.ParentId.HasValue)
                {
                    q.Where(q.ParentId == source.ParentId.Value);
                }
                else
                {
                    q.Where(q.ParentId.IsNull());
                }
                q.Where(q.SortOrder >= source.SortOrder);
                q.Where(q.Id != categoryId);
                q.OrderBy(q.SortOrder.Ascending);

                Category dest = new Category();
                if (dest.Load(q))
                {
                    SwapAndReNumberSortOrder(source, dest);
                }
            }
        }
示例#2
0
        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);
        }
示例#4
0
 public bool LoadBySlug(int storeId, string slug)
 {
     if (!string.IsNullOrEmpty(slug))
     {
         return(this.Load(CategoryQuery.FindSingleBySlug(storeId, slug)));
     }
     return(false);
 }
示例#5
0
        public static CategoryQuery FindSingleBySlug(int storeId, string slug)
        {
            CategoryQuery q = new CategoryQuery();

            q.es.Top = 1;
            q.Where(q.StoreId == storeId, q.Slug == slug);

            return(q);
        }
示例#6
0
        public static Category GetByName(int storeId, string name)
        {
            var q = new CategoryQuery();

            q.Where(q.StoreId == storeId, q.Name == name.Trim());

            var c = new Category();

            return(c.Load(q) ? c : null);
        }
示例#7
0
        public static bool SlugExists(int storeId, string slug)
        {
            slug = slug.ToLower();

            // method for testing 'exists' as recommended here: http://community.entityspaces.net/forums/16358/ShowThread.aspx#16358
            CategoryQuery q = new CategoryQuery();

            q.es.CountAll = true;
            q.Where(q.StoreId == storeId, q.Slug == slug);
            int count = (int)q.ExecuteScalar();

            return(count == 1);
        }
示例#8
0
        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);
        }
示例#9
0
        public static short GetNextSortOrder(int storeId)
        {
            //SELECT
            //MAX(SortOrder)
            //FROM DNNspot_Store_Category
            //WHERE StoreId = 1

            var q = new CategoryQuery();

            q.es.Top = 1;
            q.Select(q.SortOrder.Max().As("MaxSortValue")).Where(q.StoreId == storeId);

            var x = new Category();

            if (x.Load(q))
            {
                short next = WA.Parser.ToShort(x.GetColumn("MaxSortValue")).Value;
                return((short)(next + 1));
            }
            return(9999);
        }
        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();
            }
        }
示例#11
0
        public static Category GetOrCreateHomeCategoryForStore(Store store)
        {
            CategoryQuery q = new CategoryQuery();

            q.es.Top = 1;
            q.Where(q.StoreId == store.Id.Value, q.ParentId.IsNull(), q.IsSystemCategory == true);

            Category homeCategory = new Category();

            if (!homeCategory.Load(q))
            {
                homeCategory.StoreId          = store.Id.Value;
                homeCategory.Name             = "Store";
                homeCategory.Title            = store.Name;
                homeCategory.Slug             = "store";
                homeCategory.Description      = "Welcome to our online store!";
                homeCategory.ParentId         = null;
                homeCategory.NestingLevel     = 0;
                homeCategory.IsDisplayed      = true;
                homeCategory.IsSystemCategory = true;
                homeCategory.Save();
            }
            return(homeCategory);
        }