コード例 #1
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageModelTemplates))
            {
                return(AccessDeniedView());
            }

            var modelTemplate = _modelTemplateService.GetModelTemplateById(id);

            if (modelTemplate == null)
            {
                //No modelTemplate found with the specified id
                return(RedirectToAction("List"));
            }

            var model = modelTemplate.ToModel();


            return(View(model));
        }
コード例 #2
0
ファイル: TopicController.cs プロジェクト: yuyu2you/Caf.CMS
        protected TopicModel PrepareTopicModel(string systemName)
        {
            //load by site
            var topic = _topicService.GetTopicBySystemName(systemName, _siteContext.CurrentSite.Id);

            if (topic == null)
            {
                return(null);
            }

            var titleTag = "h3";

            if (topic.TitleTag != null)
            {
                titleTag = topic.TitleTag;
            }
            else if (!topic.RenderAsWidget)
            {
                titleTag = "h1";
            }

            var model = new TopicModel()
            {
                Id                  = topic.Id,
                SystemName          = topic.SystemName,
                IncludeInSitemap    = topic.IncludeInSitemap,
                IsPasswordProtected = topic.IsPasswordProtected,
                Title               = topic.IsPasswordProtected ? "" : topic.GetLocalized(x => x.Title),
                Body                = topic.IsPasswordProtected ? "" : topic.GetLocalized(x => x.Body),
                MetaKeywords        = topic.GetLocalized(x => x.MetaKeywords),
                MetaDescription     = topic.GetLocalized(x => x.MetaDescription),
                MetaTitle           = topic.GetLocalized(x => x.MetaTitle),
                TitleTag            = titleTag,
            };
            //template
            var templateCacheKey = string.Format(ModelCacheEventConsumer.ARTICLE_TEMPLATE_MODEL_KEY, topic.TopicTemplateId);

            model.TopicTemplateViewPath = _cacheManager.Get(templateCacheKey, () =>
            {
                var template = _modelTemplateService.GetModelTemplateById(topic.TopicTemplateId);
                if (template == null)
                {
                    template = _modelTemplateService.GetAllModelTemplates().FirstOrDefault();
                }
                return(template.ViewPath);
            });
            return(model);
        }
コード例 #3
0
        public ActionResult Category(int categoryId, ArticleCatalogPagingFilteringModel command, string filter)
        {
            var category = _articlecategoryService.GetArticleCategoryById(categoryId);

            if (category == null || category.Deleted)
            {
                return(HttpNotFound());
            }

            //判断内容访问权限,实际项目中需求及去掉注释启用
            //It allows him to preview a category before publishing
            //if (!category.Published )
            //    return HttpNotFound();

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

            //site mapping
            if (!_siteMappingService.Authorize(category))
            {
                return(HttpNotFound());
            }

            //'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);
            }

            model.DisplayFilter = _catalogSettings.FilterEnabled;
            model.ShowSubcategoriesAboveArticleLists = _catalogSettings.ShowSubcategoriesAboveArticleLists;

            var customerRolesIds = _services.WorkContext.CurrentUser.UserRoles.Where(x => x.Active).Select(x => x.Id).ToList();

            //subcategories子分类
            //model.SubCategories = _articlecategoryService
            //    .GetAllArticleCategoriesByParentCategoryId(categoryId)
            //    .Select(x =>
            //    {
            //        var subCatName = x.GetLocalized(y => y.Name);
            //        var subCatModel = new ArticleCategoryModel.SubCategoryModel()
            //        {
            //            Id = x.Id,
            //            Name = subCatName,
            //            SeName = x.GetSeName(),
            //        };

            //        //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);
            //        subCatModel.PictureModel = _services.Cache.Get(categoryPictureCacheKey, () =>
            //        {
            //            var picture = _pictureService.GetPictureById(x.PictureId.GetValueOrDefault());
            //            var pictureModel = new PictureModel()
            //            {
            //                PictureId = x.PictureId.GetValueOrDefault(),
            //                FullSizeImageUrl = _pictureService.GetPictureUrl(picture),
            //                ImageUrl = _pictureService.GetPictureUrl(picture, targetSize: pictureSize),
            //                Title = string.Format(T("Media.Category.ImageLinkTitleFormat"), subCatName),
            //                AlternateText = string.Format(T("Media.Category.ImageAlternateTextFormat"), subCatName)
            //            };
            //            return pictureModel;
            //        });

            //        return subCatModel;
            //    })
            //    .ToList();

            // Articles
            if (filter.HasValue())
            {
                //var context = new FilterArticleContext
                //{
                //    ParentCategoryID = category.Id,
                //    CategoryIds = new List<int> { category.Id },
                //    Criteria = _filterService.Deserialize(filter),
                //    OrderBy = command.OrderBy
                //};

                //if (_catalogSettings.ShowArticlesFromSubcategories)
                //    context.CategoryIds.AddRange(_helper.GetChildCategoryIds(category.Id));

                //var filterQuery = _filterService.ArticleFilter(context);
                //var articles = new PagedList<Article>(filterQuery, command.PageIndex, command.PageSize);

                //model.Articles = _helper.PrepareArticleOverviewModels(
                //    articles,
                //    prepareColorAttributes: true,
                //    prepareClients: command.ViewMode.IsCaseInsensitiveEqual("list")).ToList();
                //model.PagingFilteringContext.LoadPagedList(articles);
            }
            else
            {
                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();

                var articles = _articleService.SearchArticles(ctx2);

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

                model.PagingFilteringContext.LoadPagedList(articles);
            }



            // template
            var templateCacheKey = string.Format(ModelCacheEventConsumer.ARTICLECATEGORY_TEMPLATE_MODEL_KEY, category.ModelTemplateId);
            var templateViewPath = _services.Cache.Get(templateCacheKey, () =>
            {
                var template = _modelTemplateService.GetModelTemplateById(category.ModelTemplateId);
                if (template == null)
                {
                    template = _modelTemplateService.GetAllModelTemplates().FirstOrDefault();
                }
                return(template.ViewPath);
            });

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

            if (IsAjaxRequest())
            {
                return(Json(model));
            }
            else
            {
                return(View(templateViewPath, model));
            }
        }