public PagedProductCategoryListResult SearchByFilter(ProductCategoriesFilter filter) { IQueryable <ProductCategory> query = _productCategoriesRepository.SearchByFilter(filter).OrderBy(entity => entity.Order); PagedProductCategoryListResult result = new PagedProductCategoryListResult(); result.TotalRecords = query.Count(); result.Entities.AddRange(query.Skip((filter.PaginationFilter.PageNumber - 1) * filter.PaginationFilter.PageSize).Take(filter.PaginationFilter.PageSize)); return(result); }
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); } }
private void AddChildCategories(List <VerticalCategorySelectorItemViewModel> verticalCategorySelectorItemViewModels, ProductCategory parentCategory, int?categoryId) { PagedProductCategoryListResult childCategories = _productCategoriesBL.SearchByFilter(new ProductCategoriesFilter { ParentId = parentCategory.Id, IgnoreParentId = false, IncludeDeleted = false, Publish = true }); foreach (ProductCategory productCategory in childCategories.Entities) { VerticalCategorySelectorItemViewModel verticalCategorySelectorItemViewModel = new VerticalCategorySelectorItemViewModel { Id = productCategory.Id, Name = productCategory.Name, Selected = productCategory.Id == categoryId }; verticalCategorySelectorItemViewModels.Add(verticalCategorySelectorItemViewModel); AddChildCategories(verticalCategorySelectorItemViewModel.ChildCategories, productCategory, categoryId); } }
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)); }