コード例 #1
0
        /// <summary>
        /// 跟新菜单Id
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task UpdateMenuId(UpdateMenuId_XncfModuleDto dto)
        {
            var xncfModule = await base.GetObjectAsync(z => z.Uid == dto.Uid).ConfigureAwait(false);

            xncfModule.UpdateMenuId(dto.MenuId);
            await SaveObjectAsync(xncfModule).ConfigureAwait(false);
        }
コード例 #2
0
        /// <summary>
        /// 安装模块之后,安装菜单
        /// </summary>
        /// <param name="register"></param>
        /// <returns></returns>
        public async Task InstallMenuAsync(IXncfRegister register, InstallOrUpdate installOrUpdate)
        {
            var topMenu = await _sysMenuService.Value.GetObjectAsync(z => z.MenuName == "扩展模块").ConfigureAwait(false);

            var currentMenu = await _sysMenuService.Value.GetObjectAsync(z => z.ParentId == topMenu.Id && z.MenuName == register.MenuName).ConfigureAwait(false);

            SysMenuDto menuDto;

            if (installOrUpdate == InstallOrUpdate.Update && currentMenu != null)
            {
                //更新菜单
                menuDto          = _sysMenuService.Value.Mapper.Map <SysMenuDto>(currentMenu);
                menuDto.MenuName = register.MenuName; //更新菜单名称
                menuDto.Icon     = register.Icon;     //更新菜单图标
            }
            else
            {
                //新建菜单
                var icon  = register.Icon.IsNullOrEmpty() ? "fa fa-bars" : register.Icon;
                var order = 20;
                switch (register.Uid)
                {
                case SiteConfig.SYSTEM_XNCF_MODULE_SERVICE_UID:
                    order = 160;
                    break;

                case SiteConfig.SYSTEM_XNCF_MODULE_AREAS_ADMIN_UID:
                    order = 150;
                    break;

                default:
                    break;
                }
                menuDto = new SysMenuDto(true, null, register.MenuName, topMenu.Id, $"/Admin/XncfModule/Start/?uid={register.Uid}", icon, order, true, null);
            }

            var sysMemu = await _sysMenuService.Value.CreateOrUpdateAsync(menuDto).ConfigureAwait(false);

            if (installOrUpdate == InstallOrUpdate.Install)
            {
                //更新菜单信息
                SysPermissionDto sysPermissionDto = new SysPermissionDto()
                {
                    IsMenu       = true,
                    ResourceCode = sysMemu.ResourceCode,
                    RoleId       = "1",
                    RoleCode     = "administrator",
                    PermissionId = sysMemu.Id
                };
                SenparcEntities db = _serviceProvider.GetService <SenparcEntities>();
                db.SysPermission.Add(new SysPermission(sysPermissionDto));
                await db.SaveChangesAsync();

                var updateMenuDto = new UpdateMenuId_XncfModuleDto(register.Uid, sysMemu.Id);
                await base.UpdateMenuIdAsync(updateMenuDto).ConfigureAwait(false);
            }
        }