コード例 #1
0
ファイル: AdminMenuService.cs プロジェクト: codific/mvc567
        public async Task <TShemeModel> GetRoleShemeOrDefaultAsync <TShemeModel>(string role)
        {
            try
            {
                AdminNavigationScheme resultScheme = (await this.StandardRepository.QueryAsync <AdminNavigationScheme>(
                                                          x => x.Role.Name == role,
                                                          null,
                                                          x => x.Include(y => y.Menus).ThenInclude(z => ((SidebarMenuSectionItem)z).Children))).FirstOrDefault();

                if (resultScheme == null)
                {
                    resultScheme = (await this.StandardRepository.QueryAsync <AdminNavigationScheme>(
                                        x => !x.RoleId.HasValue,
                                        null,
                                        x => x.Include(y => y.Menus).ThenInclude(z => ((SidebarMenuSectionItem)z).Children))).FirstOrDefault();
                }

                if (resultScheme == null)
                {
                    return(default(TShemeModel));
                }

                resultScheme.Menus = resultScheme.Menus.OrderBy(x => x.Order).ToList();
                foreach (var menuSection in resultScheme.Menus)
                {
                    menuSection.Children = menuSection.Children.OrderBy(x => x.Order).ToList();
                }

                return(this.Mapper.Map <TShemeModel>(resultScheme));
            }
            catch (Exception ex)
            {
                await this.LogErrorAsync(ex, nameof(this.GetRoleShemeOrDefaultAsync));

                return(default(TShemeModel));
            }
        }
コード例 #2
0
        private async Task InitDefaultAdminNavigationMenusAsync()
        {
            AdminNavigationScheme defaultScheme = new AdminNavigationScheme();
            AdminNavigationScheme adminSheme    = new AdminNavigationScheme();
            var defaultDashboardSection         = new SidebarMenuSectionItem()
            {
                Title          = "Dashboard",
                ItemArea       = "Admin",
                ItemController = "AdminDashboard",
                ItemAction     = "Index",
                Order          = 0,
                Single         = true,
                Icon           = "mdi mdi-television",
            };
            var defaultAdminDashboardSection = new SidebarMenuSectionItem()
            {
                Title          = "Dashboard",
                ItemArea       = "Admin",
                ItemController = "AdminDashboard",
                ItemAction     = "Index",
                Order          = 0,
                Single         = true,
                Icon           = "mdi mdi-television",
            };

            var usersSection = new SidebarMenuSectionItem
            {
                Title          = "Users",
                ItemController = "AdminUsers",
                Order          = 8,
                Single         = false,
                Icon           = "mdi mdi-account",
                Children       = new List <SidebarNavigationLinkItem>(),
            };

            var allUsersNavigationItem = new SidebarNavigationLinkItem
            {
                Title          = "All Users",
                ItemAction     = "GetAll",
                ItemController = "AdminUsers",
                ItemArea       = "Admin",
            };

            usersSection.Children.Add(allUsersNavigationItem);

            var settingsSection = new SidebarMenuSectionItem
            {
                Title          = "Settings",
                ItemController = "AdminSettings",
                Order          = 10,
                Single         = false,
                Icon           = "mdi mdi-settings",
                Children       = new List <SidebarNavigationLinkItem>(),
            };

            var languagesSettingsNavigationItem = new SidebarNavigationLinkItem
            {
                Title          = "Languages",
                ItemAction     = "GetAll",
                ItemController = "AdminLanguages",
                ItemArea       = "Admin",
                Order          = 5,
            };

            var menuSettingsNavigationItem = new SidebarNavigationLinkItem
            {
                Title          = "Menus",
                ItemAction     = "GetAll",
                ItemController = "AdminNavigationMenu",
                ItemArea       = "Admin",
                Order          = 10,
            };

            var logsSettingsNavigationItem = new SidebarNavigationLinkItem
            {
                Title          = "Logs",
                ItemAction     = "GetAll",
                ItemController = "AdminLogs",
                ItemArea       = "Admin",
                Order          = 15,
            };

            var systemConstantsSettingsNavigationItem = new SidebarNavigationLinkItem
            {
                Title          = "System Constants",
                ItemAction     = "GetAll",
                ItemController = "AdminSystemConstants",
                ItemArea       = "Admin",
                Order          = 20,
            };

            settingsSection.Children.Add(languagesSettingsNavigationItem);
            settingsSection.Children.Add(menuSettingsNavigationItem);
            settingsSection.Children.Add(logsSettingsNavigationItem);
            settingsSection.Children.Add(systemConstantsSettingsNavigationItem);

            defaultScheme.Name  = "Default";
            defaultScheme.Menus = new List <SidebarMenuSectionItem>();
            defaultScheme.Menus.Add(defaultDashboardSection);

            adminSheme.Name  = "Admin Menu";
            adminSheme.Role  = this.context.Roles.Where(x => x.Name == UserRoles.Admin).FirstOrDefault();
            adminSheme.Menus = new List <SidebarMenuSectionItem>();
            adminSheme.Menus.Add(defaultAdminDashboardSection);
            adminSheme.Menus.Add(usersSection);
            adminSheme.Menus.Add(settingsSection);

            this.context.AdminNavigationSchemes.Add(defaultScheme);
            this.context.AdminNavigationSchemes.Add(adminSheme);

            await this.context.SaveChangesAsync();
        }