Esempio n. 1
0
        private HomePageViewModel BuildHomePageViewModel(string searchTerm, int?parentCategoryId, int?pageNumber)
        {
            HomePageViewModel viewModel = new HomePageViewModel();

            viewModel.RootCategories = _productCategoriesBL.GetCategories(null).Select(productCategory => new HorizontalCategoryItemViewModel
            {
                ProductCategory = productCategory,
                IsSelected      = false
            }).ToList();

            viewModel.SelectedCategory = null;
            ProductsFilter productsFilter = new ProductsFilter
            {
                Text     = searchTerm,
                Publish  = true,
                ParentId = parentCategoryId
            };

            productsFilter.PaginationFilter.PageNumber = pageNumber == null ? 1 : pageNumber.Value;
            productsFilter.PaginationFilter.PageSize   = ApplicationSettings.Instance.AppSettings.DefaultPageSize;

            PagedProductListResult pagedProductListResult = _productsBL.Get(productsFilter);

            viewModel.Products = pagedProductListResult.Entities;
            viewModel.PaginationFilterViewModel = new HomePagePaginationFilterViewModel
            {
                PageNumber       = productsFilter.PaginationFilter.PageNumber,
                TotalRecords     = pagedProductListResult.TotalRecords,
                PageSize         = productsFilter.PaginationFilter.PageSize,
                SearchTerm       = searchTerm,
                ParentCategoryId = parentCategoryId
            };

            if (parentCategoryId.HasValue)
            {
                viewModel.ParentCategories = _productCategoriesBL.GetParentCategories(parentCategoryId.Value);
                viewModel.SelectedCategory = _productCategoriesBL.GetById(parentCategoryId.Value);
                viewModel.ParentCategories.Add(viewModel.SelectedCategory);
                viewModel.ChildCategories = _productCategoriesBL.SearchByFilter(new ProductCategoriesFilter
                {
                    ParentId       = parentCategoryId,
                    IncludeDeleted = false,
                    Publish        = true
                }).Entities;
            }
            else
            {
                viewModel.ParentCategories = new List <ProductCategory>();
                viewModel.ChildCategories  = new List <ProductCategory>();
            }

            return(viewModel);
        }
Esempio n. 2
0
        public IList <ProductCategoryAutocompleteItem> SearchCategories(string term)
        {
            List <ProductCategory> productCategories = _productCategoriesBL.SearchCategories(term);

            List <ProductCategoryAutocompleteItem> result = productCategories.Select(category => new ProductCategoryAutocompleteItem
            {
                Id               = category.Id,
                Name             = category.Name,
                ParentCategories = _productCategoriesBL.GetParentCategories(category.Id).Select(parentCategory => parentCategory.Name).ToArray()
            }).ToList();

            return(result);
        }
Esempio n. 3
0
        public ActionResult Create(int?categoryId)
        {
            ProductCreateOrEditViewModel model = new ProductCreateOrEditViewModel(categoryId);

            model.Currencies = _currenciesBL.GetAll();

            if (categoryId.HasValue)
            {
                model.CategorySelectorViewModel.Name             = _productCategoriesBL.GetById(categoryId.Value).Name;
                model.CategorySelectorViewModel.ParentCategories = _productCategoriesBL.GetParentCategories(categoryId.Value).Select(parentCategory => parentCategory.Name).ToArray();
            }

            return(View("Edit", model));
        }
Esempio n. 4
0
        public ActionResult Index([FromUri] int?parentId)
        {
            object parentCategoryIdObject = TempData[Constants.TempDataKeys.PRODUCT_CATEGORIES_PARENT_ID];

            int?parentCategoryId = (int?)parentCategoryIdObject ?? parentId;

            List <ProductCategory> parentCategories = new List <ProductCategory>();

            if (parentCategoryId.HasValue)
            {
                parentCategories.AddRange(_productCategoriesBL.GetParentCategories(parentCategoryId.Value));
                parentCategories.Add(_productCategoriesBL.GetById(parentCategoryId.Value));
            }

            List <ProductCategoriesBreadCrumbItem> breadCrumbs = new List <ProductCategoriesBreadCrumbItem>(
                parentCategories.Select(x => new ProductCategoriesBreadCrumbItem
            {
                Id   = x.Id,
                Name = x.Name
            }));

            ProductCategoriesBreadCrumbItem rootCategoriesBreadCrumbItem = new ProductCategoriesBreadCrumbItem
            {
                Id   = null,
                Name = ".."
            };

            breadCrumbs.Insert(0, rootCategoriesBreadCrumbItem);

            ProductCategoriesViewModel model = new ProductCategoriesViewModel
            {
                BreadCrumbItems  = breadCrumbs,
                ParentCategoryId = parentCategoryId
            };

            return(View(model));
        }