Exemplo n.º 1
0
        private static IEnumerable<Menu> TreeViewAutharized(IEnumerable<Menu> pureList, int? parentId, IAuthenticationValidator validator, ref string role)
        {
            List<Menu> list = pureList.Where(i => i.ParentId == parentId).ToList();

            List<Menu> authenticatedList = new List<Menu>();
            foreach (Menu menu in list)
            {
                if (String.IsNullOrEmpty(menu.Action) || validator.IsAuthenticated(role, menu.Controller, menu.Action))
                {
                    authenticatedList.Add(menu);
                }
            }

            foreach (var menuItem in authenticatedList)
            {
                var childs = TreeViewAutharized(pureList, menuItem.Id, validator, ref role);
                menuItem.Childs.AddRange(childs);
            }
            return authenticatedList;
        }