public static string GetCategoryNameWithPrefix(this ArticleCategory category, IArticleCategoryService categoryService, IDictionary <int, ArticleCategory> mappedCategories = null) { string result = string.Empty; while (category != null) { if (String.IsNullOrEmpty(result)) { result = category.GetFullCategoryName(); } else { result = "--" + result; } int parentId = category.ParentCategoryId; if (mappedCategories == null) { category = categoryService.GetArticleCategoryById(parentId); } else { category = mappedCategories.ContainsKey(parentId) ? mappedCategories[parentId] : categoryService.GetArticleCategoryById(parentId); } } return(result); }
public static string GetCategoryBreadCrumb(this ArticleCategory category, IArticleCategoryService categoryService, IDictionary <int, ArticleCategory> mappedCategories = null) { string result = string.Empty; while (category != null && !category.Deleted) { // codehint: sm-edit if (String.IsNullOrEmpty(result)) { result = category.GetFullCategoryName(); } else { result = category.GetFullCategoryName() + " >> " + result; } int parentId = category.ParentCategoryId; if (mappedCategories == null) { category = categoryService.GetArticleCategoryById(parentId); } else { category = mappedCategories.ContainsKey(parentId) ? mappedCategories[parentId] : categoryService.GetArticleCategoryById(parentId); } } return(result); }
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); }
public ActionResult Create(ArticleCategoryModel model, bool continueEditing, bool continueCreate, FormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var category = model.ToEntity(); if (category.ParentCategoryId != 0 && category.ChannelId == 0) { category.ChannelId = _categoryService.GetArticleCategoryById(category.ParentCategoryId).ChannelId; } category.AddEntitySysParam(); _categoryService.InsertArticleCategory(category); //search engine name model.SeName = category.ValidateSeName(model.SeName, category.Name, true); _urlRecordService.SaveSlug(category, model.SeName, 0); //locales UpdateLocales(category, model); //update picture seo file name UpdatePictureSeoNames(category); //ACL (customer roles) UpdateCategoryAcl(category, model); //SiteMap UpdateSiteMappings(category, model); _categoryService.UpdateArticleCategory(category); _eventPublisher.Publish(new ModelBoundEvent(model, category, form)); //activity log _userActivityService.InsertActivity("AddNewArticleCategory", _localizationService.GetResource("ActivityLog.AddNewArticleCategory"), category.Name); NotifySuccess(_localizationService.GetResource("Admin.ContentManagement.ArticleCategorys.Added")); if (continueCreate) { return(RedirectToAction("Create", new { channelId = model.ChannelId })); } return(continueEditing ? RedirectToAction("Edit", new { id = category.Id }) : RedirectToAction("Center", new { channelId = model.ChannelId })); } //templates PrepareTemplatesModel(model); //channel PrepareChannelsModel(model); //parent categories if (model.ParentCategoryId.HasValue) { var parentCategory = _categoryService.GetArticleCategoryById(model.ParentCategoryId.Value); if (parentCategory != null && !parentCategory.Deleted) { model.ParentCategoryBreadcrumb = parentCategory.GetCategoryBreadCrumb(_categoryService); } else { model.ParentCategoryId = 0; } } PrepareCategoryModel(model, null); //ACL PrepareAclModel(model, null, true); //Sites PrepareSitesMappingModel(model, null, true); return(View(model)); }