public virtual ActionResult AssociateArticleToCustomerRolePopupList(DataSourceRequest command,
                                                                            CustomerRoleModel.AssociateArticleToCustomerRoleModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedKendoGridJson());
            }

            //a contributor should have access only to his articles
            if (_workContext.CurrentContributor != null)
            {
                model.SearchContributorId = _workContext.CurrentContributor.Id;
            }

            var articles = _articleService.SearchArticles(
                categoryIds: new List <int> {
                model.SearchCategoryId
            },
                publisherId: model.SearchPublisherId,
                storeId: model.SearchStoreId,
                contributorId: model.SearchContributorId,
                articleType: model.SearchArticleTypeId > 0 ? (ArticleType?)model.SearchArticleTypeId : null,
                keywords: model.SearchArticleName,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize,
                showHidden: true
                );
            var gridModel = new DataSourceResult();

            gridModel.Data  = articles.Select(x => x.ToModel());
            gridModel.Total = articles.TotalCount;

            return(Json(gridModel));
        }
        public virtual ActionResult AssociateArticleToCustomerRolePopup(string btnId, string articleIdInput,
                                                                        string articleNameInput, CustomerRoleModel.AssociateArticleToCustomerRoleModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var associatedArticle = _articleService.GetArticleById(model.AssociatedToArticleId);

            if (associatedArticle == null)
            {
                return(Content("Cannot load a article"));
            }

            //a contributor should have access only to his articles
            if (_workContext.CurrentContributor != null && associatedArticle.ContributorId != _workContext.CurrentContributor.Id)
            {
                return(Content("This is not your article"));
            }

            //a contributor should have access only to his articles
            model.IsLoggedInAsContributor = _workContext.CurrentContributor != null;
            ViewBag.RefreshPage           = true;
            ViewBag.articleIdInput        = articleIdInput;
            ViewBag.articleNameInput      = articleNameInput;
            ViewBag.btnId       = btnId;
            ViewBag.articleId   = associatedArticle.Id;
            ViewBag.articleName = associatedArticle.Name;
            return(View(model));
        }
        public virtual ActionResult AssociateArticleToCustomerRolePopup()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var model = new CustomerRoleModel.AssociateArticleToCustomerRoleModel();

            //a contributor should have access only to his articles
            model.IsLoggedInAsContributor = _workContext.CurrentContributor != null;

            //categories
            model.AvailableCategories.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);

            foreach (var c in categories)
            {
                model.AvailableCategories.Add(c);
            }

            //publishers
            model.AvailablePublishers.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var publishers = SelectListHelper.GetPublisherList(_publisherService, _cacheManager, true);

            foreach (var m in publishers)
            {
                model.AvailablePublishers.Add(m);
            }

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            //contributors
            model.AvailableContributors.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var contributors = SelectListHelper.GetContributorList(_contributorService, _cacheManager, true);

            foreach (var v in contributors)
            {
                model.AvailableContributors.Add(v);
            }

            //article types
            model.AvailableArticleTypes = ArticleType.SimpleArticle.ToSelectList(false).ToList();
            model.AvailableArticleTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            return(View(model));
        }