Esempio n. 1
0
        private async Task <List <LangInput> > GetAvailableContents(Menu menu)
        {
            var list     = new List <LangInput>();
            var allLangs = await _applicationLanguageManager.GetLanguagesAsync(AbpSession.TenantId);

            foreach (var applicationLanguage in allLangs)
            {
                var content = _menuContentRepository.FirstOrDefault(a => a.Lang == applicationLanguage.Name && a.MenuId == menu.Id);
                if (content == null)
                {
                    list.Add(new LangInput()
                    {
                        DisplayText = "",
                        Lang        = applicationLanguage.Name,
                        Icon        = applicationLanguage.Icon,
                    });
                }
                else
                {
                    list.Add(new LangInput()
                    {
                        DisplayText = content.Text,
                        Icon        = applicationLanguage.Icon,
                        Lang        = applicationLanguage.Name,
                        Id          = content.Id
                    });
                }
            }
            return(list);
        }
Esempio n. 2
0
        private async Task <MenuSection> CreateMenuSection(Category category, Menu menu)
        {
            var section   = MenuSection.CreateMenuSectionWithCategory(category.Name, menu, category);
            var sectionId = await _menuManager.AddSectionAsync(section);

            if (section.Id == 0)
            {
                section = _menuSectionRepository.FirstOrDefault(sectionId);
            }
            return(section);
        }
Esempio n. 3
0
        private async Task RemoveSectionsAndContentsFromMenu(Menu menu)
        {
            var sections = await _menuSectionRepository.GetAllListAsync(a => a.MenuId == menu.Id);

            foreach (var sectionItem in sections)
            {
                await RemoveSectionItemsFromSection(sectionItem);

                await _menuSectionRepository.DeleteAsync(sectionItem);
            }
        }
Esempio n. 4
0
        public async Task <int> AddMenu(MenuInput input)
        {
            int  id;
            Menu menu;

            if (input.Id == 0)
            {
                menu = new Menu()
                {
                    MenuName = input.Name.Sluggify(),
                    IsActive = input.IsActive,
                    Id       = input.Id,
                    Order    = _menuRepository.Count() + 1
                };
                id = await _menuManager.AddMenuAsync(menu);
            }
            else
            {
                menu          = _menuRepository.Get(input.Id);
                menu.IsActive = input.IsActive;
                menu.MenuName = input.Name.Sluggify();
                id            = await _menuManager.AddMenuAsync(menu);
            }

            foreach (var inputAvailableLang in input.AvailableLangs)
            {
                if (string.IsNullOrEmpty(inputAvailableLang.DisplayText))
                {
                    continue;
                }
                if (inputAvailableLang.Id == 0)
                {
                    await _menuManager.AddMenuContentAsync(MenuContent.CreateMenuContent(inputAvailableLang.Lang, inputAvailableLang.DisplayText, "", menu));
                }
                else
                {
                    var langContent = _menuContentRepository.Get(inputAvailableLang.Id);
                    langContent.Text = inputAvailableLang.DisplayText;
                    await _menuManager.AddMenuContentAsync(langContent);
                }
            }
            return(id);
        }