public async Task OnGetAsync() { if (!string.IsNullOrEmpty(Id)) { var entity = await _sysMenuService.GetObjectAsync(_ => _.Id == Id); SysButtons = await _sysButtonService.GetFullListAsync(_ => _.MenuId == Id); SysMenuDto = _sysMenuService.Mapper.Map <SysMenuDto>(entity); } else { SysMenuDto = new SysMenuDto() { Visible = true }; SysButtons = new List <SysButton>() { new SysButton() }; } }
/// <summary> /// 删除模块 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IActionResult> OnPostDeleteAsync(int id) { var module = await _xncfModuleService.GetObjectAsync(z => z.Id == id).ConfigureAwait(false); if (module == null) { throw new Exception("模块未添加!"); } //删除菜单 Func <Task> uninstall = async() => { //删除菜单 SysPermissionService sysPermissionService = _serviceProvider.GetService <SysPermissionService>(); var menu = await _sysMenuService.GetObjectAsync(z => z.Id == module.MenuId).ConfigureAwait(false); if (menu != null) { //删除菜单 await _sysMenuService.DeleteObjectAsync(menu).ConfigureAwait(false); //删除权限数据 await sysPermissionService.DeleteAllAsync(_ => _.PermissionId == menu.Id); //更新菜单缓存 await _sysMenuService.GetMenuDtoByCacheAsync(true).ConfigureAwait(false); } await _xncfModuleService.DeleteObjectAsync(module).ConfigureAwait(false); }; //尝试从已加载的模块中执行删除过程 var register = XncfRegisterManager.RegisterList.FirstOrDefault(z => z.Uid == module.Uid); if (register == null) { //直接删除,如dll已经不存在,可能引发此问题,只能在当前系统内直接执行删除 await uninstall().ConfigureAwait(false); } else { await register.UninstallAsync(_serviceProvider, uninstall).ConfigureAwait(false); } return(Ok(true)); }
/// <summary> /// 删除模块 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IActionResult> OnPostDeleteAsync(int id) { var module = await _xscfModuleService.GetObjectAsync(z => z.Id == id).ConfigureAwait(false); if (module == null) { throw new Exception("模块未添加!"); } //删除菜单 Func <Task> uninstall = async() => { //删除菜单 var menu = await _sysMenuService.GetObjectAsync(z => z.Id == module.MenuId).ConfigureAwait(false); if (menu != null) { //删除菜单 await _sysMenuService.DeleteObjectAsync(menu).ConfigureAwait(false); //更新菜单缓存 await _sysMenuService.GetMenuDtoByCacheAsync(true).ConfigureAwait(false); } await _xscfModuleService.DeleteObjectAsync(module).ConfigureAwait(false); }; //尝试从已加载的模块中执行删除过程 var register = Senparc.Scf.XscfBase.Register.RegisterList.FirstOrDefault(z => z.Uid == module.Uid); if (register == null) { //直接删除,如dll已经不存在,可能引发此问题,只能在当前系统内直接执行删除 await uninstall().ConfigureAwait(false); } else { await register.UninstallAsync(_serviceProvider, uninstall).ConfigureAwait(false); } return(RedirectToPage("Index")); }