public static IEnumerable<ListMenuPageItemModel> Flatten(ListMenuPageItemModel root, List<ListMenuPageItemModel> items, IEnumerable<Page> selectedItems)
 {
     var children = items.Where(item => item.Page.ParentPageId == root.Page.Id).ToList();
     foreach (var child in children)
     {
         child.Children = Flatten(child, items,selectedItems);
         child.IsSelected = selectedItems != null && selectedItems.FirstOrDefault(page => page.Id == child.Page.Id) != null;
         yield return child;
     }
 }
        public static IEnumerable <ListMenuPageItemModel> Flatten(ListMenuPageItemModel root, List <ListMenuPageItemModel> items, IEnumerable <Page> selectedItems)
        {
            var children = items.Where(item => item.Page.ParentPageId == root.Page.Id).ToList();

            foreach (var child in children)
            {
                child.Children   = Flatten(child, items, selectedItems);
                child.IsSelected = selectedItems != null && selectedItems.FirstOrDefault(page => page.Id == child.Page.Id) != null;
                yield return(child);
            }
        }