public virtual async Task <IActionResult> ItemsByKeyword(string keyword)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var model = new KnowledgebaseHomePageModel();

            if (!string.IsNullOrEmpty(keyword))
            {
                var categories = await _knowledgebaseService.GetPublicKnowledgebaseCategoriesByKeyword(keyword);

                var allCategories = await _knowledgebaseService.GetPublicKnowledgebaseCategories();

                categories.ForEach(x => model.Items.Add(new KnowledgebaseItemModel
                {
                    Name                 = x.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id),
                    Id                   = x.Id,
                    SeName               = x.GetLocalized(y => y.SeName, _workContext.WorkingLanguage.Id),
                    IsArticle            = false,
                    FormattedBreadcrumbs = x.GetFormattedBreadCrumb(allCategories, ">")
                }));

                var articles = await _knowledgebaseService.GetPublicKnowledgebaseArticlesByKeyword(keyword);

                foreach (var item in articles)
                {
                    var kbm = new KnowledgebaseItemModel
                    {
                        Name                 = item.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id),
                        Id                   = item.Id,
                        SeName               = item.GetLocalized(y => y.SeName, _workContext.WorkingLanguage.Id),
                        IsArticle            = true,
                        FormattedBreadcrumbs = (await _knowledgebaseService.GetPublicKnowledgebaseCategory(item.ParentCategoryId))?.GetFormattedBreadCrumb(allCategories, ">") +
                                               " > " + item.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id)
                    };
                    model.Items.Add(kbm);
                }
            }
            model.CurrentCategoryId = "[NONE]";
            model.SearchKeyword     = keyword;

            return(View("List", model));
        }
Esempio n. 2
0
        public IViewComponentResult Invoke(KnowledgebaseHomePageModel model)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(Content(""));
            }

            var articles = _knowledgebaseService.GetHomepageKnowledgebaseArticles();

            foreach (var article in articles)
            {
                var a = new KnowledgebaseItemModel
                {
                    Id        = article.Id,
                    Name      = article.GetLocalized(y => y.Name),
                    SeName    = article.GetLocalized(y => y.SeName),
                    IsArticle = true
                };

                model.Items.Add(a);
            }

            return(View(model));
        }
Esempio n. 3
0
        public async Task <IViewComponentResult> InvokeAsync(KnowledgebaseHomePageModel model)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(Content(""));
            }

            var articles = await _knowledgebaseService.GetHomepageKnowledgebaseArticles();

            foreach (var article in articles)
            {
                var a = new KnowledgebaseItemModel
                {
                    Id        = article.Id,
                    Name      = article.GetLocalized(y => y.Name, _workContext.WorkingLanguage.Id),
                    SeName    = article.GetLocalized(y => y.SeName, _workContext.WorkingLanguage.Id),
                    IsArticle = true
                };

                model.Items.Add(a);
            }

            return(View(model));
        }