Пример #1
0
        public static CategoriesJson Categories(string accountNameKey, List <CategoryModel> categoriesIn)
        {
            var categoriesObjectOut = new CategoriesJson();

            categoriesObjectOut.categories = new List <CategorizationListItemJson>();

            foreach (CategoryModel categoryModel in categoriesIn)
            {
                var categoryListItem = new CategorizationListItemJson
                {
                    //id = categoryModel.CategoryID.ToString(),
                    name               = categoryModel.CategoryName,
                    nameKey            = categoryModel.CategoryNameKey,
                    fullyQualifiedName = categoryModel.FullyQualifiedName
                };


                //Get listing image records for each object from Table Storage
                categoryListItem.images = Dynamics.Images.BuildDynamicImagesListForJson(accountNameKey, "category", categoryModel.CategoryID.ToString(), true);


                categoriesObjectOut.categories.Add(categoryListItem);
            }



            categoriesObjectOut.count = categoriesObjectOut.categories.Count;

            return(categoriesObjectOut);
        }
Пример #2
0
        public static CategoryDetailsJson Category(string accountNameKey, CategoryModel categoryIn, bool includeItems, bool includeHidden)
        {
            var categoryObjectOut = new CategoryDetailsJson();

            categoryObjectOut.category = new Models.Json.Categorization.CategoryJson();
            categoryObjectOut.category.subcategories = new List <CategorizationListItemJson>();


            #region Build out subcategorization list

            foreach (SubcategoryListModel subcategoryModel in categoryIn.Subcategories)
            {
                var subcategoryListItem = new CategorizationListItemJson
                {
                    //id = subcategoryModel.SubcategoryID.ToString(),
                    name               = subcategoryModel.SubcategoryName,
                    nameKey            = subcategoryModel.SubcategoryNameKey,
                    fullyQualifiedName = subcategoryModel.FullyQualifiedName
                };

                //Get listing images for each subcategory in the list
                subcategoryListItem.images = Dynamics.Images.BuildDynamicImagesListForJson(accountNameKey, "subcategory", subcategoryModel.SubcategoryID.ToString(), true);

                categoryObjectOut.category.subcategories.Add(subcategoryListItem);
            }

            #endregion


            #region Build out product list

            if (includeItems && categoryIn.Subcategories.Count == 0)
            {
                var account = Common.GetAccountObject(accountNameKey);

                //Search products
                string filter         = "(categoryNameKey eq '" + categoryIn.CategoryNameKey + "')";
                var    productResults = DataAccess.Search.SearchProducts(account, null, filter, "orderId asc", 0, 1000, false, null, includeHidden);

                categoryObjectOut.category.items = Dynamics.Products.TransformDynamicProductsListForJson(productResults.Results);
            }

            #endregion

            //categoryObjectOut.count = categoryObjectOut.categories.Count;

            //Get images for this category
            categoryObjectOut.category.images = Dynamics.Images.BuildDynamicImagesListForJson(accountNameKey, "category", categoryIn.CategoryID.ToString(), false);

            //categoryObjectOut.category.id = categoryIn.CategoryID.ToString();
            categoryObjectOut.category.name               = categoryIn.CategoryName;
            categoryObjectOut.category.nameKey            = categoryIn.CategoryNameKey;
            categoryObjectOut.category.fullyQualifiedName = categoryIn.FullyQualifiedName;
            categoryObjectOut.category.description        = categoryIn.Description;
            return(categoryObjectOut);
        }