ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Shared/Menu.cshtml
@using Grand.Core.Plugins
@using Grand.Services.Security
@using Grand.Services.Localization
@using Grand.Framework.Menu
@inject IPluginFinder pluginFinder
@inject IPermissionService permissionService
@inject ILocalizationService localizationService 
@{
    //load sitemap
    var siteMap = new XmlSiteMap(localizationService, permissionService);
    await siteMap.LoadFrom("~/App_Data/sitemap.config");
}

<div class="col-md-3 left_col">
    <div class="left_col scroll-view">
        <div class="navbar nav_title">
            <a href="~/Admin" class="site_title"><img src="~/administration/build/images/grandLogo.png" width="35px" height="35px" /> <span>GrandNode</span></a>
        </div>
        <div class="clearfix"></div>
        <div class="main_menu_side hidden-print main_menu" id="sidebar-menu">
            <div class="menu_section">
                <ul class="nav side-menu page-sidebar-menu">
                    @{
                        //standard (default) items
                        var rootNode = siteMap.RootNode;

                        //plugins
                        var adminMenuPlugins = pluginFinder.GetPlugins<IAdminMenuPlugin>().ToList();
                        foreach (var adminMenuPlugin in adminMenuPlugins)
                        {
                            await adminMenuPlugin.ManageSiteMap(rootNode);
                        }
                        //"Plugins" menu item should be visible when it has some child nodes
                        var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
                        if (pluginNode != null && pluginNode.Visible)
                        {
                            var hasManagePluginsPermission = await permissionService.Authorize(Grand.Services.Security.StandardPermissionProvider.ManagePlugins);
                            pluginNode.Visible = hasManagePluginsPermission && pluginNode.ChildNodes.Any(x => x.Visible);
                        }
                    }
                    @foreach (var item in rootNode.ChildNodes.Where(x => x.Visible))
                    {
                        <partial name="_MenuItem" model="item" />
                    }
                </ul>
            </div>
        </div>
    </div>
</div>