public ArticlePostModel() { Tags = new List<ArticleTagModel>(); Comments = new List<ArticleCommentModel>(); AddNewComment = new AddArticleCommentModel(); PagingFilteringContext = new ArticleCatalogPagingFilteringModel(); ArticleExtendedAttributes = new List<ArticleExtendedAttributeModel>(); }
public ActionResult ArticlesByTag(int articleTagId, ArticleCatalogPagingFilteringModel command) { var articlesTag = _articlesTagService.GetArticleTagById(articleTagId); if (articlesTag == null) { return(HttpNotFound()); } if (command.PageNumber <= 0) { command.PageNumber = 1; } var model = new ArticleByTagModel() { Id = articlesTag.Id, TagName = articlesTag.GetLocalized(y => y.Name) }; _helper.PreparePagingFilteringModel(model.PagingFilteringContext, command, new PageSizeContext { AllowUsersToSelectPageSize = _catalogSettings.ArticlesByTagAllowUsersToSelectPageSize, PageSize = _catalogSettings.ArticlesByTagPageSize, PageSizeOptions = _catalogSettings.ArticlesByTagPageSizeOptions.IsEmpty() ? _catalogSettings.DefaultPageSizeOptions : _catalogSettings.ArticlesByTagPageSizeOptions }); //articless var ctx = new ArticleSearchContext(); ctx.ArticleTagId = articlesTag.Id; ctx.LanguageId = _services.WorkContext.WorkingLanguage.Id; ctx.OrderBy = (ArticleSortingEnum)command.OrderBy; ctx.PageIndex = command.PageNumber - 1; ctx.PageSize = command.PageSize; ctx.SiteId = _services.SiteContext.CurrentSiteIdIfMultiSiteMode; ctx.VisibleIndividuallyOnly = true; var articless = _articleService.SearchArticles(ctx); model.Articles = _helper.PrepareArticlePostModels( articless).ToList(); model.PagingFilteringContext.LoadPagedList(articless); //model.PagingFilteringContext.ViewMode = viewMode; return(View(model)); }
public ActionResult AjaxHomeArticleBlock(int categoryId, int?articleThumbPictureSize, ArticleCatalogPagingFilteringModel command) { var model = new ArticleCategoryModel(); model = CategoryFilter(categoryId, articleThumbPictureSize, command); return(Json(model)); }
public ActionResult HomeRecentlyArticleViewed(int categoryId, int?articleThumbPictureSize, string partialView, ArticleCatalogPagingFilteringModel command) { var model = new ArticleCategoryModel(); model = CategoryFilter(categoryId, articleThumbPictureSize, command, partialView); return(PartialView(partialView, model)); }
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)); } }
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); }