public static MenuViewModelItem FromDomain( MenuItem item, UrlHelper url, IEnumerable <AllowedResource> allowed) { var a = new MenuViewModelItem(); a.Name = item.Name; switch (item.Type) { case MenuItemType.None: break; case MenuItemType.Catalog: a.Location = url.Action(MVC.Site.Catalog.Index()); break; case MenuItemType.Url: a.Location = item.Location; break; case MenuItemType.Page: a.Location = url.Action(MVC.Site.Page.Index(item.Location)); break; case MenuItemType.Quiz: a.Location = url.Action(MVC.Site.Quiz.Index(item.Location)); break; case MenuItemType.Award: a.Location = url.Action(MVC.Site.Award.Index(item.Location)); break; case MenuItemType.Survey: a.Location = url.Action(MVC.Site.Survey.Index(item.Location)); break; case MenuItemType.Game: a.Location = url.Action(MVC.Site.Game.Index(item.Location)); break; } if (!String.IsNullOrEmpty(a.Location)) { a.Location = a.Location.ToAbsoluteUrl(url.RequestContext.HttpContext.Request).ToString(); } if (item.Items != null && null != allowed) { a.Items = item.Items.Where(x => IsVisible(x, allowed)) .Select(x => FromDomain(x, url, allowed)) .ToList(); if (a.Items.Count == 0) { a.Items = null; } } return(a); }
protected void ResolveMenu(ActionExecutingContext filterContext, string menuId, string viewdataName) { if (String.IsNullOrEmpty(menuId)) { return; } var menu = Menus[menuId]; var key = MenuKey + menuId; var menuViewModel = Session[key] as MenuViewModel; if (null == menuViewModel || menuViewModel.Revision != menu.Document.Revision) { var allowed = MenusRepository.GetResourcesForUser(CurrentUser); menuViewModel = new MenuViewModel( menu.Items.Where(x => MenuViewModelItem.IsVisible(x, allowed)) .Select(x => MenuViewModelItem.FromDomain(x, Url, allowed)) ); menuViewModel.Revision = menu.Document.Revision; Session[key] = menuViewModel; } ViewData[viewdataName] = menuViewModel; }