|  | 
|  | 1 | +namespace LearningHub.Nhs.WebUI.Models.SideMenu | 
|  | 2 | +{ | 
|  | 3 | +    using System; | 
|  | 4 | +    using System.Collections.Generic; | 
|  | 5 | +    using System.Linq; | 
|  | 6 | +    using Microsoft.AspNetCore.Routing; | 
|  | 7 | + | 
|  | 8 | +    /// <summary> | 
|  | 9 | +    /// Defines the <see cref="SideNavigationConfiguration" />. | 
|  | 10 | +    /// </summary> | 
|  | 11 | +    public static class SideNavigationConfiguration | 
|  | 12 | +    { | 
|  | 13 | +        /// <summary> | 
|  | 14 | +        /// GetGroupedMenus. | 
|  | 15 | +        /// </summary> | 
|  | 16 | +        /// <returns>IEnumerable.</returns> | 
|  | 17 | +        public static IEnumerable<SideNavigationGroup> GetGroupedMenus() | 
|  | 18 | +        { | 
|  | 19 | +            return new List<SideNavigationGroup> | 
|  | 20 | +        { | 
|  | 21 | +            new SideNavigationGroup | 
|  | 22 | +            { | 
|  | 23 | +                GroupTitle = "Account", | 
|  | 24 | +                Items = new List<SideNavigationItem> | 
|  | 25 | +                { | 
|  | 26 | +                    new SideNavigationItem | 
|  | 27 | +                    { | 
|  | 28 | +                        Text = "Personal details", | 
|  | 29 | +                        Controller = "Account", | 
|  | 30 | +                        Action = "PersonalDetails", | 
|  | 31 | +                        IsActive = route => MatchRoute(route, "Account", "PersonalDetails"), | 
|  | 32 | +                    }, | 
|  | 33 | +                    new SideNavigationItem | 
|  | 34 | +                    { | 
|  | 35 | +                        Text = "My employment", | 
|  | 36 | +                        Controller = "Account", | 
|  | 37 | +                        Action = "MyEmployment", | 
|  | 38 | +                        IsActive = route => MatchRoute(route, "Account", "MyEmployment"), | 
|  | 39 | +                    }, | 
|  | 40 | +                    new SideNavigationItem | 
|  | 41 | +                    { | 
|  | 42 | +                        Text = "Security", | 
|  | 43 | +                        Controller = "Account", | 
|  | 44 | +                        Action = "Security", | 
|  | 45 | +                        IsActive = route => MatchRoute(route, "Account", "Security"), | 
|  | 46 | +                    }, | 
|  | 47 | +                    new SideNavigationItem | 
|  | 48 | +                    { | 
|  | 49 | +                        Text = "Notification", | 
|  | 50 | +                        Controller = "Account", | 
|  | 51 | +                        Action = "Notification", | 
|  | 52 | +                        IsActive = route => MatchRoute(route, "Account", "Notification"), | 
|  | 53 | +                    }, | 
|  | 54 | +                }, | 
|  | 55 | +            }, | 
|  | 56 | +            new SideNavigationGroup | 
|  | 57 | +            { | 
|  | 58 | +                GroupTitle = "Activity", | 
|  | 59 | +                Items = new List<SideNavigationItem> | 
|  | 60 | +                { | 
|  | 61 | +                    new SideNavigationItem | 
|  | 62 | +                    { | 
|  | 63 | +                        Text = "Recent", | 
|  | 64 | +                        Controller = "Activity", | 
|  | 65 | +                        Action = "Recent", | 
|  | 66 | +                        IsActive = route => MatchRoute(route, "Activity", "Recent"), | 
|  | 67 | +                    }, | 
|  | 68 | +                    new SideNavigationItem | 
|  | 69 | +                    { | 
|  | 70 | +                        Text = "Bookmark", | 
|  | 71 | +                        Controller = "Activity", | 
|  | 72 | +                        Action = "Bookmark", | 
|  | 73 | +                        IsActive = route => MatchRoute(route, "Activity", "Bookmark"), | 
|  | 74 | +                    }, | 
|  | 75 | +                    new SideNavigationItem | 
|  | 76 | +                    { | 
|  | 77 | +                        Text = "Certificates", | 
|  | 78 | +                        Controller = "Activity", | 
|  | 79 | +                        Action = "Certificates", | 
|  | 80 | +                        IsActive = route => MatchRoute(route, "Activity", "Certificates"), | 
|  | 81 | +                    }, | 
|  | 82 | +                    new SideNavigationItem | 
|  | 83 | +                    { | 
|  | 84 | +                        Text = "Learning history", | 
|  | 85 | +                        Controller = "Activity", | 
|  | 86 | +                        Action = "Learninghistory", | 
|  | 87 | +                        IsActive = route => MatchRoute(route, "Activity", "Learninghistory"), | 
|  | 88 | +                    }, | 
|  | 89 | +                }, | 
|  | 90 | +            }, | 
|  | 91 | +        }; | 
|  | 92 | +        } | 
|  | 93 | + | 
|  | 94 | +        /// <summary> | 
|  | 95 | +        /// GetMenuGroupByTitle. | 
|  | 96 | +        /// </summary> | 
|  | 97 | +        /// <param name="title">title.</param> | 
|  | 98 | +        /// <returns>string.</returns> | 
|  | 99 | +        public static SideNavigationGroup? GetMenuGroupByTitle(string title) | 
|  | 100 | +        { | 
|  | 101 | +            return GetGroupedMenus().FirstOrDefault(g => | 
|  | 102 | +                string.Equals(g.GroupTitle, title, StringComparison.OrdinalIgnoreCase)); | 
|  | 103 | +        } | 
|  | 104 | + | 
|  | 105 | +        private static bool MatchRoute(RouteValueDictionary route, string controller, string action) | 
|  | 106 | +        { | 
|  | 107 | +            var currentController = route["controller"]?.ToString(); | 
|  | 108 | +            var currentAction = route["action"]?.ToString(); | 
|  | 109 | + | 
|  | 110 | +            return string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase) && | 
|  | 111 | +                   string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase); | 
|  | 112 | +        } | 
|  | 113 | +    } | 
|  | 114 | +} | 
0 commit comments