Ejemplo n.º 1
0
        public ActionResult HomepageCategories()
        {
            var categories = _articlecategoryService.GetAllCategoriesDisplayedOnHomePage()
                             .Where(c => _aclService.Authorize(c) && _siteMappingService.Authorize(c))
                             .ToList();

            var listModel = categories
                            .Select(x =>
            {
                var catModel = x.ToModel();

                //prepare picture model
                int pictureSize             = _mediaSettings.CategoryThumbPictureSize;
                var categoryPictureCacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_PICTURE_MODEL_KEY, x.Id, pictureSize, true,
                                                            _services.WorkContext.WorkingLanguage.Id, _services.WebHelper.IsCurrentConnectionSecured(), _services.SiteContext.CurrentSite.Id);
                catModel.PictureModel = _services.Cache.Get(categoryPictureCacheKey, () =>
                {
                    var pictureModel = new PictureModel()
                    {
                        PictureId        = x.PictureId.GetValueOrDefault(),
                        FullSizeImageUrl = _pictureService.GetPictureUrl(x.PictureId.GetValueOrDefault()),
                        ImageUrl         = _pictureService.GetPictureUrl(x.PictureId.GetValueOrDefault(), pictureSize),
                        Title            = string.Format(T("Media.ArticleCategory.ImageLinkTitleFormat"), catModel.Name),
                        AlternateText    = string.Format(T("Media.ArticleCategory.ImageAlternateTextFormat"), catModel.Name)
                    };
                    return(pictureModel);
                });

                return(catModel);
            })
                            .ToList();

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

            return(PartialView(listModel));
        }