Beispiel #1
0
        public async Task <MenuList> GetMenuAsync()
        {
            using (MenuInfoDataProvider menuInfoDP = new MenuInfoDataProvider()) {
#pragma warning disable 0618 // Type or member is obsolete
                MenuList menu = Menu;
#pragma warning restore 0618 // Type or member is obsolete
                if (menu != null)
                {
                    await SaveMenuAsync(menu); // Legacy: the menu was saved as part of module definition, move it to MenuInfoDataProvider
                }
                else
                {
                    MenuInfo menuInfo = await menuInfoDP.GetItemAsync(ModuleGuid);

                    if (menuInfo != null)
                    {
                        menu = menuInfo.Menu;
                    }
                    else
                    {
                        menu = new MenuList();
                    }
                }
                return(menu);
            }
        }
Beispiel #2
0
        public async Task SaveMenuAsync(MenuList newMenu)
        {
            using (MenuInfoDataProvider menuInfoDP = new MenuInfoDataProvider()) {
#pragma warning disable 0618 // Type or member is obsolete
                MenuList menu = Menu;
#pragma warning restore 0618 // Type or member is obsolete
                await menuInfoDP.ReplaceItemAsync(new MenuInfo {
                    ModuleGuid = ModuleGuid,
                    Menu       = newMenu,
                });

                // get a fresh copy of the module definitions
                MenuModule menuMod = (MenuModule)await ModuleDefinition.LoadAsync(ModuleGuid);

                if (menuMod == null)
                {
                    throw new InternalError("Menu module {0} was deleted", ModuleGuid);
                }
                menuMod.NewMenuVersion();
                this.MenuVersion = menuMod.MenuVersion;
#pragma warning disable 0618                     // Type or member is obsolete
                // the menu was saved as part of module definition, move it to MenuInfoDataProvider
                this.Menu = menuMod.Menu = null; // Legacy: clear menu saved as part of module definition
#pragma warning restore 0618                     // Type or member is obsolete
                await menuMod.SaveAsync();       // save module definition (without menu)
            }
        }