Exemple #1
0
        public ActionResult RelatedArticles(int articleId, int?articleThumbPictureSize)
        {
            var articles        = new List <Article>();
            var relatedArticles = _articleService.GetRelatedArticlesByArticleId1(articleId);

            foreach (var article in _articleService.GetArticlesByIds(relatedArticles.Select(x => x.ArticleId2).ToArray()))
            {
                //ensure has ACL permission and appropriate store mapping
                if (_aclService.Authorize(article) && _siteMappingService.Authorize(article))
                {
                    articles.Add(article);
                }
            }

            if (articles.Count == 0)
            {
                return(Content(""));
            }

            var model = _helper.PrepareArticlePostModels(articles, true, false, articleThumbPictureSize).ToList();

            return(PartialView(model));
        }
        private ArticleCategoryModel CategoryFilter(int categoryId, int?articleThumbPictureSize, ArticleCatalogPagingFilteringModel command, string partialView = null)
        {
            var cacheKey = string.Format(ModelCacheEventConsumer.HOMEPAGE_TOPARTICLESMODEL_KEY, _services.WorkContext.WorkingLanguage.Id, _services.SiteContext.CurrentSite.Id, categoryId);

            if (partialView.IsEmpty())
            {
                cacheKey = string.Format(ModelCacheEventConsumer.HOMEPAGE_TOPARTICLESMODEL_PARTVIEW_KEY, _services.WorkContext.WorkingLanguage.Id, _services.SiteContext.CurrentSite.Id, categoryId, partialView);
            }
            var cachedModel = _services.Cache.Get(cacheKey, () =>
            {
                var category = _articlecategoryService.GetArticleCategoryById(categoryId);
                if (category == null || category.Deleted)
                {
                    return(null);
                }

                //Check whether the current user has a "Manage catalog" permission
                //It allows him to preview a category before publishing
                //if (!category.Published )
                //    return null;

                ////ACL (access control list)
                //if (!_aclService.Authorize(category))
                //    return null;

                //Site mapping
                if (!_siteMappingService.Authorize(category))
                {
                    return(null);
                }


                //'Continue shopping' URL
                _genericAttributeService.SaveAttribute(_services.WorkContext.CurrentUser,
                                                       SystemUserAttributeNames.LastContinueShoppingPage,
                                                       _services.WebHelper.GetThisPageUrl(false),
                                                       _services.SiteContext.CurrentSite.Id);

                if (command.PageNumber <= 0)
                {
                    command.PageNumber = 1;
                }



                var model = category.ToModel();
                _helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext
                {
                    AllowUsersToSelectPageSize = category.AllowUsersToSelectPageSize,
                    PageSize        = category.PageSize,
                    PageSizeOptions = category.PageSizeOptions
                });
                //category breadcrumb
                model.DisplayCategoryBreadcrumb = _catalogSettings.CategoryBreadcrumbEnabled;
                if (model.DisplayCategoryBreadcrumb)
                {
                    model.CategoryBreadcrumb = _helper.GetCategoryBreadCrumb(category.Id, 0);
                }

                // Articles

                var ctx2 = new ArticleSearchContext();
                if (category.Id > 0)
                {
                    ctx2.CategoryIds.Add(category.Id);
                    if (_catalogSettings.ShowArticlesFromSubcategories)
                    {
                        // include subcategories
                        ctx2.CategoryIds.AddRange(_helper.GetChildCategoryIds(category.Id));
                    }
                }

                ctx2.LanguageId = _services.WorkContext.WorkingLanguage.Id;

                ctx2.OrderBy   = (ArticleSortingEnum)command.OrderBy; // ArticleSortingEnum.Position;
                ctx2.PageIndex = command.PageNumber - 1;
                ctx2.PageSize  = command.PageSize;
                ctx2.SiteId    = _services.SiteContext.CurrentSiteIdIfMultiSiteMode;
                ctx2.Origin    = categoryId.ToString();
                ctx2.IsTop     = command.IsTop;
                ctx2.IsHot     = command.IsHot;
                ctx2.IsRed     = command.IsRed;
                ctx2.IsSlide   = command.IsSlide;
                var articles   = _articleService.SearchArticles(ctx2);

                model.PagingFilteringContext.LoadPagedList(articles);

                model.Articles = _helper.PrepareArticlePostModels(
                    articles,
                    preparePictureModel: true, articleThumbPictureSize: articleThumbPictureSize).ToList();


                // activity log
                _services.UserActivity.InsertActivity("PublicSite.ViewCategory", T("ActivityLog.PublicSite.ViewCategory"), category.Name);
                return(model);
            });

            return(cachedModel);
        }