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); }
public ActionResult VerticalCategorySelector() { int?categoryId = null; if (TempData["CategoryId"] != null) { categoryId = (int)TempData["CategoryId"]; } PagedProductCategoryListResult rootCategories = _productCategoriesBL.SearchByFilter(new ProductCategoriesFilter { ParentId = null, IgnoreParentId = false, IncludeDeleted = false, Publish = true }); VerticalCategorySelectorViewModel model = new VerticalCategorySelectorViewModel(); model.Categories = new List <VerticalCategorySelectorItemViewModel>(); foreach (ProductCategory productCategory in rootCategories.Entities) { VerticalCategorySelectorItemViewModel verticalCategorySelectorItemViewModel = new VerticalCategorySelectorItemViewModel { Id = productCategory.Id, Name = productCategory.Name, Selected = productCategory.Id == categoryId }; model.Categories.Add(verticalCategorySelectorItemViewModel); AddChildCategories(verticalCategorySelectorItemViewModel.ChildCategories, productCategory, categoryId); } return(PartialView("_verticalCategorySelector", model)); }
private void ProcessCategory(List <DynamicNode> nodes, string parentKey, int?parentCategoryId) { PagedProductCategoryListResult pagedProductCategoryListResult = _productCategoriesBL.SearchByFilter(new ProductCategoriesFilter(int.MaxValue) { Publish = true, IncludeDeleted = false, ParentId = parentCategoryId }); foreach (ProductCategory productCategory in pagedProductCategoryListResult.Entities) { DynamicNode productCategoryNode = new DynamicNode { ParentKey = parentKey, Title = productCategory.Name, Key = "ProductCategory_" + productCategory.Id, Action = "Index", Controller = "Home" }; productCategoryNode.RouteValues.Add("parentCategoryId", productCategory.Id); nodes.Add(productCategoryNode); List <Product> products = _productsBL.Get(new ProductsFilter { ParentId = productCategory.Id, Publish = true }).Entities; foreach (Product product in products) { DynamicNode productNode = new DynamicNode { ParentKey = productCategoryNode.Key, Title = product.Name, Key = productCategoryNode.Key + "_Product_" + product.Id, Controller = "Home", Action = "Details" }; productNode.RouteValues.Add("productId", product.Id); productNode.RouteValues.Add("categoryId", productCategory.Id); nodes.Add(productNode); } ProcessCategory(nodes, productCategoryNode.Key, productCategory.Id); } }