Example #1
0
        public ActionResult List(DataTablesParam dataTableParam, CategoryListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var categories       = _categoryService.GetAllCategories(model.SearchCategoryName, 0, int.MaxValue, true, model.SearchAlias, model.SearchChannelId, true, false);
            var mappedCategories = categories.ToDictionary(x => x.Id);
            Dictionary <int, string> breadCrumbDir = new Dictionary <int, string>();

            var total  = categories.TotalCount;
            var result = new DataTablesData
            {
                iTotalRecords        = total,
                iTotalDisplayRecords = total,
                sEcho  = dataTableParam.sEcho,
                aaData = categories.Select(x =>
                {
                    var categoryModel         = x.ToModel();
                    categoryModel.Breadcrumb  = x.GetCategoryBreadCrumb(_categoryService, mappedCategories);
                    categoryModel.ChannelName = x.Channel.Title;
                    return(categoryModel);
                }).Cast <object>().ToArray(),
            };

            return(new JsonResult
            {
                Data = result
            });
        }
        /// <summary>
        /// Save the articleCategory napping for an entity
        /// </summary>
        /// <typeparam name="T">Entity type</typeparam>
        /// <param name="entity">The entity</param>
        /// <param name="selectedArticleCategoryIds">Array of selected articleCategory ids</param>
        public virtual void SaveArticleCategoryMappings <T>(T entity, int[] selectedArticleCategoryIds) where T : BaseEntity
        {
            var existingArticleCategoryMappings = GetArticleCategoryMappings(entity);
            var allArticleCategorys             = _articleCategoryService.GetAllCategories();

            foreach (var articleCategory in allArticleCategorys)
            {
                if (selectedArticleCategoryIds != null && selectedArticleCategoryIds.Contains(articleCategory.Id))
                {
                    if (existingArticleCategoryMappings.Where(sm => sm.ArticleCategoryId == articleCategory.Id).Count() == 0)
                    {
                        InsertArticleCategoryMapping(entity, articleCategory.Id);
                    }
                }
                else
                {
                    var articleCategoryMappingToDelete = existingArticleCategoryMappings.Where(sm => sm.ArticleCategoryId == articleCategory.Id).FirstOrDefault();
                    if (articleCategoryMappingToDelete != null)
                    {
                        DeleteArticleCategoryMapping(articleCategoryMappingToDelete);
                    }
                }
            }
        }