Пример #1
0
        public async Task UpdateMenuItemsWhenCategoryChange(int pageId, int?oldCategoryId, int newCategoryId)
        {
            var section = _menuSectionRepository.FirstOrDefault(a => a.CategoryId == oldCategoryId) ??
                          _menuSectionRepository.FirstOrDefault(a => a.CategoryId == newCategoryId);

            if (section == null)
            {
                return;
            }

            var elementFromOldSection = await _menuSectionItemRepository.FirstOrDefaultAsync(a => a.SectionId == section.Id && a.PageId == pageId);


            var newSection = _menuSectionRepository.FirstOrDefault(a => a.CategoryId == newCategoryId);

            if (newSection == null)
            {
                return;
            }
            if (elementFromOldSection == null)
            {
                var page = _pageRepository.FirstOrDefault(pageId);

                var newSectionItem   = MenuSectionItem.CreateMenuSectionItem(page.Name, newSection, pageId);
                var newSectionEntity = await CreateSectionItem(page, newSection, page.Contents.ToList());

                if (newSectionItem.Id == 0)
                {
                    newSectionItem = _menuSectionItemRepository.FirstOrDefault(newSectionEntity.Id);
                }
                elementFromOldSection = newSectionItem;
            }
            elementFromOldSection.SectionId = newSection.Id;
        }
Пример #2
0
        private async Task CreateEditSectionItemContent(Content pageContent, MenuSectionItem menuSectionItem)
        {
            var menuSectionItemContent =
                MenuSectionItemContent.CreateMenuSectionItemContent(DynamicCreated, pageContent.Lang,
                                                                    menuSectionItem);

            menuSectionItemContent.PageId = pageContent.PageId;
            await _menuManager.AddMenuItemContentAsync(menuSectionItemContent);
        }
Пример #3
0
        private async Task <MenuSectionItem> CreateSectionItem(Page page, MenuSection section, List <Content> pageContents)
        {
            var menuSectionItem = MenuSectionItem.CreateMenuSectionItem(page.Name, section, page.Id);

            var id = await _menuManager.AddMenuItemAsync(menuSectionItem);

            if (menuSectionItem.Id == 0)
            {
                menuSectionItem = _menuSectionItemRepository.FirstOrDefault(id);
            }

            foreach (var pageContent in pageContents)
            {
                await CreateEditSectionItemContent(pageContent, menuSectionItem);
            }
            return(menuSectionItem);
        }
Пример #4
0
        public void ValidateMenuItem(MenuSectionItem sectionItem)
        {
            if (sectionItem.MenuSection == null)
            {
                throw new UserFriendlyException("InvalidMenuItemSection");
            }
            if (sectionItem.Id != 0)
            {
                return;
            }
            var found = _menuSectionItemRepository.FirstOrDefault(a => a.Name == sectionItem.Name);

            if (found == null)
            {
                return;
            }
            throw new UserFriendlyException("RepeatedMenuItemName");
        }
Пример #5
0
        public async Task <int> AddMenuItemAsync(MenuSectionItem sectionItem)
        {
            //_menuPolicy.ValidateMenuItem(sectionItem);

            var itemFound = _menuSectionItemRepository.FirstOrDefault(a => a.Name == sectionItem.Name);

            if (itemFound != null)
            {
                itemFound.Name        = sectionItem.Name;
                itemFound.MenuSection = sectionItem.MenuSection;
                await _menuSectionItemRepository.InsertOrUpdateAndGetIdAsync(itemFound);

                return(itemFound.Id);
            }

            var id = await _menuSectionItemRepository.InsertOrUpdateAndGetIdAsync(sectionItem);

            return(id);
        }
Пример #6
0
        public async Task SetItemForPage(Page page)
        {
            var section = await _menuSectionRepository.FirstOrDefaultAsync(a => a.CategoryId == page.CategoryId);

            if (section == null)
            {
                return;
            }
            var pageContents      = _pageContentRepository.GetAllList(a => a.PageId == page.Id);
            var sectionItemEntity = MenuSectionItem.CreateMenuSectionItem(page.Name, section, page.Id);
            var id = await AddMenuItemAsync(sectionItemEntity);

            if (sectionItemEntity.Id == 0)
            {
                sectionItemEntity = _menuSectionItemRepository.FirstOrDefault(id);
            }
            foreach (var pageContent in pageContents)
            {
                await
                AddMenuItemContentAsync(
                    MenuSectionItemContent.CreateMenuSectionItemContent(pageContent.Title, pageContent.Lang,
                                                                        sectionItemEntity));
            }
        }