// // GET: /ContentBlocks/CategoryMenu/ public ActionResult Index(ContentBlock block) { CategoryMenuViewModel model = new CategoryMenuViewModel(); LoadMenu(model, block); return(View(model)); }
protected override string RenderView() { var slug = Request.Params["slug"]; var menuModel = new CategoryMenuViewModel { ShowCategoryCounts = Convert.ToBoolean(Settings["ShowCategoryCount"]), ShowProductCounts = Convert.ToBoolean(Settings["ShowProductCount"]), Title = Convert.ToString(Settings["Title"]), CategoryMenuMode = Convert.ToString(Settings["CategoryMenuMode"]), ShowHomeLink = Convert.ToBoolean(Settings["HomeLink"]), MaximumDepth = Convert.ToInt32(Settings["MaximumDepth"]), ChildrenOfCategory = Convert.ToString(Settings["ChildrenOfCategory"]) }; foreach ( var bvin in Convert.ToString(Settings["SelectedCategories"]) .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { if (!menuModel.SelectedCategories.Contains(bvin)) { menuModel.SelectedCategories.Add(bvin); } } return(MvcRenderingEngine.Render("CategoryMenu", "Index", new { model = menuModel, slug })); }
public List <CategoryMenuViewModel> GetAllCategoryForMenu_() { var listResult = new List <CategoryMenuViewModel>(); //var parent = _dbSet.Where(x => x.Parent.Id == null).ToList(); //foreach (var item in parent) //{ // var sample = new CategoryMenuViewModel { Name = item.Name }; // sample.Category = _dbSet.Where(x => x.Parent.Id == item.Id).ToList(); // listResult.Add(sample); //} var list = _dbSet.ToList(); var parentList = list.Where(x => x.Parent == null).ToList(); var childreenList = list.Where(x => x.Parent != null).ToList(); foreach (var item in parentList) { var sample = new CategoryMenuViewModel { Name = item.Name }; sample.Category = childreenList.Where(x => x.Parent.Id == item.Id).ToList(); listResult.Add(sample); } return(listResult); }
private void AddCategoryCollection(CategoryMenuViewModel model, List <CategorySnapshot> allCats, List <CategorySnapshot> cats, int currentDepth, int maxDepth) { if (cats != null) { foreach (CategorySnapshot c in cats) { if (c.Hidden == false) { AddSingleLink(model, c, allCats); if ((maxDepth == 0) | (currentDepth + 1 < maxDepth)) { List <CategorySnapshot> children = MTApp.CatalogServices.Categories.FindVisibleChildren(c.Bvin); if (children != null) { if (children.Count > 0) { model.sb.Append("<ul>" + System.Environment.NewLine); AddCategoryCollection(model, allCats, children, currentDepth + 1, maxDepth); model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>"); } } } }
private void LoadPeersAndChildren(CategoryMenuViewModel model) { var allCats = HccApp.CatalogServices.Categories.FindAll(); // Get Current Category // Trick system into accepting root category of zero which never exists in database var currentCategory = Category.FindInList(allCats, model.CurrentId) ?? new CategorySnapshot { Bvin = VirtualRootCategoryBvin }; // Find the trail from this category back to the root of the site var trail = new List <CategorySnapshot>(); BuildParentTrail(allCats, model.CurrentId, trail); if (trail.Count < 1) { // Load Roots Only LoadRoots(model); } else { var neighbors = GetPeerSet(allCats, currentCategory); model.MenuItem = BuildParentsPeersChildren(neighbors, currentCategory, model.ShowProductCounts); } }
private void LoadAllCategories(CategoryMenuViewModel model, int maxDepth) { List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAll(); List <CategorySnapshot> children = Category.FindChildrenInList(allCats, "0", false); AddCategoryCollection(model, allCats, children, 0, maxDepth); }
public CategoryMenuViewModel GetCategoryMenu(int id) { var viewModel = new CategoryMenuViewModel(); var categories = this.GetAllCategorySummaries(); var realCategories = new List <CategorySummaryDto>(); realCategories.Add(new CategorySummaryDto { Id = 0, Name = "Home", IsCurrentPage = id == 0 }); foreach (var categorySummaryDto in categories) { if (categorySummaryDto.Id == id) { categorySummaryDto.IsCurrentPage = true; } realCategories.Add(categorySummaryDto); } viewModel.Categories = realCategories; return(viewModel); }
private void ExpandInTrail(CategoryMenuViewModel model, List <CategorySnapshot> allCats, List <CategorySnapshot> cats, List <CategorySnapshot> trail) { if (cats != null) { foreach (CategorySnapshot c in cats) { if (c.Hidden == false) { AddSingleLink(model, c, allCats); if (IsInTrail(c.Bvin, trail)) { List <CategorySnapshot> children = Category.FindChildrenInList(allCats, c.Bvin, false); if (children != null) { if (children.Count > 0) { model.sb.Append("<ul>" + System.Environment.NewLine); ExpandInTrail(model, allCats, children, trail); model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>"); } } } }
private void LoadRoots(CategoryMenuViewModel model) { var cats = HccApp.CatalogServices.Categories.FindVisibleChildren(VirtualRootCategoryBvin); var menu = BuildItemsTree(cats, cats, 1, 1, model.CurrentId, model.ShowProductCounts); model.MenuItem = menu; }
private void LoadAllCategories(CategoryMenuViewModel model) { var allCats = HccApp.CatalogServices.Categories.FindAll(); var children = Category.FindChildrenInList(allCats, VirtualRootCategoryBvin, false); var menu = BuildItemsTree(allCats, children, 0, model.MaximumDepth, model.CurrentId, model.ShowProductCounts); model.MenuItem = menu; }
private void LoadMenu(CategoryMenuViewModel model, string slug) { model.CurrentId = LocateCurrentCategory(slug); var isAllProducts = false; // Load Title if (!string.IsNullOrEmpty(model.Title)) { model.Title = string.Format(VIEW_TITLE, model.Title); } var mode = model.CategoryMenuMode; switch (mode) { case "1": // All Categories LoadAllCategories(model); isAllProducts = true; break; case "2": // Peers, Children and Parents LoadPeersAndChildren(model); break; case "3": // Show root and expanded children LoadRootPlusExpandedChildren(model); break; case "4": LoadSelectedCategories(model); break; case "5": LoadChildrenOfSelected(model); break; case "0": default: // Root Categories Only LoadRoots(model); break; } if (model.ShowProductCounts) { //Set Product Count SetProductsCount(model, model.MenuItem, isAllProducts); } if (model.ShowHomeLink) { AddHomeLink(model); } }
private static CategoryMenuViewModel createNewCategory(ProductObject product) { var c = new CategoryMenuViewModel { Category = product.Category }; c.Products.Add(product); return(c); }
private void LoadChildrenOfSelected(CategoryMenuViewModel model) { var listAll = HccApp.CatalogServices.Categories.FindAll(); var children = Category.FindChildrenInList(listAll, model.ChildrenOfCategory, false); var menu = BuildItemsTree(listAll, children, 0, model.MaximumDepth, model.CurrentId, model.ShowProductCounts); model.MenuItem = menu; }
public string Render(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, MerchantTribe.Commerce.Content.ContentBlock block) { this.MTApp = app; this.ViewBag = viewBag; CategoryMenuViewModel model = new CategoryMenuViewModel(); LoadMenu(model, block); return(Render(model)); }
private void LoadSelectedCategories(CategoryMenuViewModel model) { var listAll = HccApp.CatalogServices.Categories.FindAll(); var selectedCategories = listAll.Where(cat => model.SelectedCategories.Contains(cat.Bvin)).ToList(); var menu = BuildItemsTree(listAll, selectedCategories, 0, model.MaximumDepth, model.CurrentId, model.ShowProductCounts); model.MenuItem = menu; }
private void LoadMenu(CategoryMenuViewModel model, ContentBlock b) { model.CurrentId = LocateCurrentCategory(); if (b != null) { // Load Title string title = b.BaseSettings.GetSettingOrEmpty("Title"); if (title.Trim().Length > 0) { model.Title = "<h4>" + title + "</h4>"; } model.ShowProductCounts = b.BaseSettings.GetBoolSetting("ShowProductCount"); model.ShowCategoryCounts = b.BaseSettings.GetBoolSetting("ShowCategoryCount"); model.sb.Append("<ul>"); if (b.BaseSettings.GetBoolSetting("HomeLink") == true) { AddHomeLink(model); } string mode = b.BaseSettings.GetSettingOrEmpty("CategoryMenuMode"); switch (mode) { case "0": // Root Categories Only LoadRoots(model); break; case "1": // All Categories LoadAllCategories(model, b.BaseSettings.GetIntegerSetting("MaximumDepth")); break; case "2": // Peers, Children and Parents LoadPeersAndChildren(model); break; case "3": // Show root and expanded children LoadRootPlusExpandedChildren(model); break; default: // All Categories LoadRoots(model); break; } model.sb.Append("</ul>"); } }
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); }
public string Render(CategoryMenuViewModel model) { StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"categorymenu\">"); sb.Append("<div class=\"decoratedblock\">"); if (!string.IsNullOrEmpty(model.Title)) { sb.Append(model.Title); } sb.Append(model.Contents); sb.Append("</div>"); sb.Append("</div>"); return(sb.ToString()); }
public async Task <IViewComponentResult> InvokeAsync() { var accessories = await _categoryService.All(CategoryType.Accessory.ToString()); var games = await _categoryService.All(CategoryType.Game.ToString()); var consoles = await _categoryService.All(CategoryType.Console.ToString()); var viewModel = new CategoryMenuViewModel { Games = games.Select(c => c.Name).ToList(), Consoles = consoles.Select(c => c.Name).ToList(), Accessories = accessories.Select(c => c.Name).ToList(), }; return(View("_MainMenu", viewModel)); }
public IViewComponentResult Invoke() { //if (TempData["currentSex"] == null) { TempData["currentSex"] = "0"; } //var sexId = int.Parse(TempData["currentSex"].ToString()); int _currentSex = (HttpContext.Session.GetInt32("sex").HasValue) ? (HttpContext.Session.GetInt32("sex").Value) : 0; int _currentCat = (HttpContext.Session.GetInt32("category").HasValue) ? (HttpContext.Session.GetInt32("category").Value) : 0; CategoryMenuViewModel categoryMenuView = new CategoryMenuViewModel { CurrentCategory = _currentCat, CurrentSex = _currentSex, CategoriesSex = _categoryRepository.CategoriesbySex(_currentSex) }; return(View(categoryMenuView)); }
private void LoadRootPlusExpandedChildren(CategoryMenuViewModel model) { var allCats = HccApp.CatalogServices.Categories.FindAll(); // Get Current Category var currentCategory = Category.FindInList(allCats, model.CurrentId) ?? new CategorySnapshot { Bvin = VirtualRootCategoryBvin }; // Find the trail from this category back to the root of the site var trail = new List <CategorySnapshot>(); BuildParentTrail(allCats, model.CurrentId, trail); var roots = Category.FindChildrenInList(allCats, VirtualRootCategoryBvin, false); model.MenuItem = BuildItemsTree(allCats, roots, trail, currentCategory.Bvin, model.ShowProductCounts); }
private void AddSingleLink(CategoryMenuViewModel model, CategorySnapshot c, List <CategorySnapshot> allCats) { if (c.Bvin == model.CurrentId) { model.sb.Append("<li class=\"current\">"); } else { model.sb.Append("<li>"); } string title = c.MetaTitle; string text = c.Name; int childCount = 0; if (model.ShowProductCounts) { childCount += (MTApp.CatalogServices.CategoriesXProducts.FindForCategory(c.Bvin, 1, int.MaxValue).Count); } if (model.ShowCategoryCounts) { childCount += Category.FindChildrenInList(allCats, c.Bvin, false).Count; } if (childCount > 0) { text += " (" + childCount.ToString() + ")"; } string url = UrlRewriter.BuildUrlForCategory(c, MTApp.CurrentRequestContext.RoutingContext); bool openNew = false; if (c.SourceType == CategorySourceType.CustomLink) { openNew = c.CustomPageOpenInNewWindow; } model.sb.Append("<a href=\"" + url + "\" title=\"" + title + "\">" + text + "</a>"); }
private void RenderPeersChildren(CategoryMenuViewModel model, CategoryPeerSet neighbors, CategorySnapshot currentCategory, List <CategorySnapshot> allCats) { // No Parents, start with peers foreach (CategorySnapshot peer in neighbors.Peers) { if (!peer.Hidden) { AddSingleLink(model, peer, allCats); if (peer.Bvin == currentCategory.Bvin) { // Load Children if (neighbors.Children.Count > 0) { bool initialized = false; foreach (CategorySnapshot child in neighbors.Children) { if (!child.Hidden) { if (!initialized) { model.sb.Append("<ul>" + System.Environment.NewLine); initialized = true; } AddSingleLink(model, child, allCats); model.sb.Append("</li>" + System.Environment.NewLine); } } if (initialized) { model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>" + System.Environment.NewLine); } } }
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; } } }
public ActionResult Index(CategoryMenuViewModel model, string slug) { LoadMenu(model, slug); return(View(model)); }
private void LoadRootPlusExpandedChildren(CategoryMenuViewModel model) { List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAll(); // Get Current Category CategorySnapshot currentCategory = Category.FindInList(allCats, model.CurrentId); if (currentCategory != null) { if (currentCategory.Bvin != string.Empty) { model.CurrentId = currentCategory.Bvin; } // Find the trail from this category back to the root of the site List <CategorySnapshot> trail = new List <CategorySnapshot>(); BuildParentTrail(allCats, model.CurrentId, ref trail); if (trail == null) { trail = new List <CategorySnapshot>(); } if (trail.Count < 1) { // Load Roots Only LoadRoots(model); } else { string StartingRootCategoryId = currentCategory.Bvin; StartingRootCategoryId = trail[trail.Count - 1].Bvin; List <CategorySnapshot> roots = Category.FindChildrenInList(allCats, "0", false); if (roots != null) { model.sb.Append("<ul>" + System.Environment.NewLine); foreach (CategorySnapshot c in roots) { if (IsInTrail(c.Bvin, trail)) { AddSingleLink(model, c, allCats); List <CategorySnapshot> children = new List <CategorySnapshot>(); children = Category.FindChildrenInList(allCats, StartingRootCategoryId, false); if (children != null) { model.sb.Append("<ul>" + System.Environment.NewLine); ExpandInTrail(model, allCats, children, trail); model.sb.Append("</ul>" + System.Environment.NewLine); } model.sb.Append("</li>"); break; } } model.sb.Append("</ul>" + System.Environment.NewLine); } } } else { model.sb.Append("Invalid Category Id. Contact Administrator"); } }
private void AddHomeLink(CategoryMenuViewModel model) { model.sb.Append("<li>"); model.sb.Append("<a href=\"" + MTApp.StoreUrl(false, false) + "\" title=\"Home\">Home</a>"); model.sb.Append("</li>"); }
private void LoadPeersAndChildren(CategoryMenuViewModel model) { List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAll(); // Get Current Category CategorySnapshot currentCategory = Category.FindInList(allCats, model.CurrentId); // Trick system into accepting root category of zero which never exists in database if (model.CurrentId == "0") { currentCategory = new CategorySnapshot(); currentCategory.Bvin = "0"; } if (currentCategory != null) { if (currentCategory.Bvin != string.Empty) { model.CurrentId = currentCategory.Bvin; } // Find the trail from this category back to the root of the site List <CategorySnapshot> trail = new List <CategorySnapshot>(); BuildParentTrail(allCats, model.CurrentId, ref trail); if (trail == null) { trail = new List <CategorySnapshot>(); } if (trail.Count < 1) { // Load Roots Only LoadRoots(model); } else { CategoryPeerSet neighbors = GetPeerSet(allCats, currentCategory); if (trail.Count == 1) { // special case where we want only peers and children RenderPeersChildren(model, neighbors, currentCategory, allCats); } else { if (trail.Count >= 3) { if (neighbors.Children.Count < 1) { // Special case where we are at the end of the tree and have // no children. Reset neighbors to parent's bvin CategorySnapshot parent = Category.FindInList(allCats, currentCategory.ParentId); if (parent == null) { parent = new CategorySnapshot(); } neighbors = GetPeerSet(allCats, parent); RenderParentsPeersChildren(model, neighbors, trail[1], allCats); } else { RenderParentsPeersChildren(model, neighbors, currentCategory, allCats); } } else { // normal load of peers RenderParentsPeersChildren(model, neighbors, currentCategory, allCats); } } } } else { model.sb.Append("Invalid Category Id. Contact Administrator"); } }
private void RenderParentsPeersChildren(CategoryMenuViewModel model, CategoryPeerSet neighbors, CategorySnapshot currentCategory, List <CategorySnapshot> allCats) { if (neighbors.Parents.Count < 1) { RenderPeersChildren(model, neighbors, currentCategory, allCats); } else { // Add Parents foreach (CategorySnapshot parent in neighbors.Parents) { if (!parent.Hidden) { AddSingleLink(model, parent, allCats); // Add Peers if (parent.Bvin == currentCategory.ParentId) { bool peerInitialized = false; foreach (CategorySnapshot peer in neighbors.Peers) { if (!peer.Hidden) { if (!peerInitialized) { model.sb.Append("<ul>"); peerInitialized = true; } AddSingleLink(model, peer, allCats); if (peer.Bvin == currentCategory.Bvin) { // Load Children if (neighbors.Children.Count > 0) { bool childInitialized = false; foreach (CategorySnapshot child in neighbors.Children) { if (!child.Hidden) { if (!childInitialized) { model.sb.Append("<ul>" + System.Environment.NewLine); childInitialized = true; } AddSingleLink(model, child, allCats); model.sb.Append("</li>" + System.Environment.NewLine); } } if (childInitialized) { model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>" + System.Environment.NewLine); } } if (peerInitialized) { model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>" + System.Environment.NewLine); } } }
private void LoadRoots(CategoryMenuViewModel model) { List <CategorySnapshot> cats = MTApp.CatalogServices.Categories.FindVisibleChildren("0"); AddCategoryCollection(model, cats, cats, 1, 1); }