private CategoryMenuItemViewModel BuildItemsTree(List <CategorySnapshot> listAll, List <CategorySnapshot> catToDisplay, int currentDepth, int maximumDepth, string currentId, bool isDisplayProductsCount) { var result = new CategoryMenuItemViewModel(); foreach (var c in catToDisplay) { CategoryMenuItemViewModel item; if ((maximumDepth == 0) || (currentDepth + 1 < maximumDepth)) { item = BuildItemsTree(listAll, Category.FindChildrenInList(listAll, c.Bvin, false), currentDepth + 1, maximumDepth, currentId, isDisplayProductsCount); } else { item = new CategoryMenuItemViewModel(); } item.Title = c.Name; item.Description = c.Description; item.Url = UrlRewriter.BuildUrlForCategory(c); if (isDisplayProductsCount) { item.Bvin = c.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(c.Bvin, false); } if (c.Bvin == currentId) { item.IsCurrent = true; } result.Items.Add(item); } return(result); }
private void AddHomeLink(CategoryMenuViewModel model) { if (model.MenuItem == null) { model.MenuItem = new CategoryMenuItemViewModel(); } var item = new CategoryMenuItemViewModel { Title = Localization.GetString("Home"), Url = Url.Content("~") }; model.MenuItem.Items.Insert(0, item); }
private List <CategoryMenuItemViewModel> LoadDrillDownCategories(string catId) { var cats = HccApp.CatalogServices.Categories.FindVisibleChildren(catId); return(cats.Select(c => { var cat = new CategoryMenuItemViewModel { Title = c.Name, Description = c.Description, Url = UrlRewriter.BuildUrlForCategory(c) }; return cat; }).ToList()); }
private int GetProductsCount(CategoryMenuItemViewModel category) { var totalCount = 0; foreach (var item in category.Items) { totalCount = item.ProductsCount; if (!item.Items.Any() || item.Items.Count != 0) { totalCount += GetProductsCount(item); } } if (category.Items == null || !category.Items.Any()) { totalCount += category.ProductsCount; } category.ProductsCount = totalCount; category.Title += " (" + totalCount + ")"; return(totalCount); }
private CategoryMenuItemViewModel BuildItemsTree(List <CategorySnapshot> allCats, List <CategorySnapshot> children, List <CategorySnapshot> trail, string currentId, bool isDisplayProductsCount) { var result = new CategoryMenuItemViewModel(); foreach (var c in children) { CategoryMenuItemViewModel item = null; if (IsInTrail(c.Bvin, trail)) { var newChildren = Category.FindChildrenInList(allCats, c.Bvin, false); if (newChildren != null && newChildren.Count > 0) { item = BuildItemsTree(allCats, newChildren, trail, currentId, isDisplayProductsCount); } } if (item == null) { item = new CategoryMenuItemViewModel(); } item.Title = c.Name; item.Description = c.Description; item.Url = UrlRewriter.BuildUrlForCategory(c); if (isDisplayProductsCount) { item.Bvin = c.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(c.Bvin, false); } if (c.Bvin == currentId) { item.IsCurrent = true; } result.Items.Add(item); } return(result); }
private CategoryMenuItemViewModel BuildPeersAndChildren(CategoryPeerSet neighbors, CategorySnapshot currentCategory, bool isDisplayProductsCount) { var result = new CategoryMenuItemViewModel(); foreach (var peer in neighbors.Peers) { var item = new CategoryMenuItemViewModel(); item.Title = peer.Name; item.Description = peer.Description; item.Url = UrlRewriter.BuildUrlForCategory(peer); if (peer.Bvin == currentCategory.Bvin) { item.IsCurrent = true; // Load Children foreach (var c in neighbors.Children) { var childItem = new CategoryMenuItemViewModel(); childItem.Title = c.Name; childItem.Description = c.Description; if (isDisplayProductsCount) { item.Bvin = c.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(c.Bvin, false); } childItem.Url = UrlRewriter.BuildUrlForCategory(c); item.Items.Add(childItem); } } if (isDisplayProductsCount) { item.Bvin = peer.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(peer.Bvin, false); } result.Items.Add(item); } return(result); }
private CategoryMenuItemViewModel BuildParentsPeersChildren(CategoryPeerSet neighbors, CategorySnapshot currentCategory, bool isDisplayProductsCount) { CategoryMenuItemViewModel result; if (neighbors.Parents.Count > 0) { result = new CategoryMenuItemViewModel(); foreach (var parent in neighbors.Parents) { CategoryMenuItemViewModel item; if (parent.Bvin == currentCategory.ParentId) { item = BuildPeersAndChildren(neighbors, currentCategory, isDisplayProductsCount); } else { item = new CategoryMenuItemViewModel(); } item.Title = parent.Name; item.Description = parent.Description; item.Url = UrlRewriter.BuildUrlForCategory(parent); if (isDisplayProductsCount) { item.Bvin = parent.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(parent.Bvin, false); } result.Items.Add(item); } } else { result = BuildPeersAndChildren(neighbors, currentCategory, isDisplayProductsCount); } return(result); }
private void SetProductsCount(CategoryMenuViewModel model, CategoryMenuItemViewModel outMenu, bool isAllProducts) { CategoryMenuItemViewModel allMenu; if (!isAllProducts) { var allCats = HccApp.CatalogServices.Categories.FindAll(); var children = Category.FindChildrenInList(allCats, VirtualRootCategoryBvin, false); allMenu = BuildItemsTree(allCats, children, 0, model.MaximumDepth, model.CurrentId, model.ShowProductCounts); } else { allMenu = model.MenuItem; } GetProductsCount(allMenu); foreach (var menu in outMenu.Items) { if (allMenu != null) { menu.ProductsCount = allMenu.Items.FirstOrDefault(x => x.Bvin == menu.Bvin).ProductsCount; menu.Title = allMenu.Items.FirstOrDefault(x => x.Bvin == menu.Bvin).Title; } } if (allMenu != null) { if (allMenu.Bvin == outMenu.Bvin) { outMenu.ProductsCount = allMenu.ProductsCount; outMenu.Title = allMenu.Title; } } }