// Clones and populates route values into each NavItem private void PopulateRouteValues(NavItem[] items) { foreach (var item in items) { var newRoutes = item.RouteValues != null ? new RouteValueDictionary(item.RouteValues) : new RouteValueDictionary(); var routeValues = GetRouteValues(); if (routeValues.ContainsKey(item.Context) && routeValues[item.Context] != null) { foreach (var value in routeValues[item.Context]) { newRoutes[value.Key] = value.Value; } } item.RouteValues = newRoutes; } }
/// <summary> /// Removes a previously added NavItem from the specified navigation context /// </summary> /// <param name="navContext">The context the NavItem belongs to</param> /// <param name="item">The item to be removed</param> /// <returns>true on exists/success</returns> public bool RemoveNavItem(string navContext, NavItem item) { if (!_navItems.ContainsKey(navContext)) return false; return _navItems[navContext].Remove(item); }
// Filters out NavItems that require roles the current user does not have private NavItem[] FilterByRoles(NavItem[] items) { string[] roles; try { roles = Roles.GetRolesForUser(); } catch { return items; } var allowedItems = items.Where(i => MatchRolesCriteria(roles, i.Roles)).ToArray(); return allowedItems; }
/// <summary> /// Adds a NavItem to the specified navigation context /// </summary> /// <param name="navContext">The context this NavItem belongs to</param> /// <param name="item">The NavItem to be added</param> public void AddNavItem(string navContext, NavItem item) { if (!_navItems.ContainsKey(navContext)) _navItems.Add(navContext, new List<NavItem>()); _navItems[navContext].Add(item); }