public virtual async Task <IActionResult> ProductAddPopupList(AddProductToManufacturerSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageManufacturers))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = await _manufacturerModelFactory.PrepareAddProductToManufacturerListModelAsync(searchModel);

            return(Json(model));
        }
        public virtual IActionResult ProductAddPopupList(AddProductToManufacturerSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers))
            {
                return(AccessDeniedKendoGridJson());
            }

            //prepare model
            var model = _manufacturerModelFactory.PrepareAddProductToManufacturerListModel(searchModel);

            return(Json(model));
        }
        /// <summary>
        /// Prepare paged product list model to add to the manufacturer
        /// </summary>
        /// <param name="searchModel">Product search model to add to the manufacturer</param>
        /// <returns>Product list model to add to the manufacturer</returns>
        public virtual AddProductToManufacturerListModel PrepareAddProductToManufacturerListModel(AddProductToManufacturerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get products
            var products = _productService.SearchProducts(showHidden: true,
                                                          categoryIds: new List <int> {
                searchModel.SearchCategoryId
            },
                                                          manufacturerId: searchModel.SearchManufacturerId,
                                                          storeId: searchModel.SearchStoreId,
                                                          vendorId: searchModel.SearchVendorId,
                                                          productType: searchModel.SearchProductTypeId > 0 ? (ProductType?)searchModel.SearchProductTypeId : null,
                                                          keywords: searchModel.SearchProductName,
                                                          pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new AddProductToManufacturerListModel
            {
                //fill in model values from the entity
                Data  = products.Select(product => product.ToModel <ProductModel>()),
                Total = products.TotalCount
            };

            return(model);
        }
        /// <summary>
        /// Prepare product search model to add to the manufacturer
        /// </summary>
        /// <param name="searchModel">Product search model to add to the manufacturer</param>
        /// <returns>Product search model to add to the manufacturer</returns>
        public virtual AddProductToManufacturerSearchModel PrepareAddProductToManufacturerSearchModel(AddProductToManufacturerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available manufacturers
            _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers);

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare available product types
            _baseAdminModelFactory.PrepareProductTypes(searchModel.AvailableProductTypes);

            //prepare page parameters
            searchModel.SetPopupGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare paged product list model to add to the manufacturer
        /// </summary>
        /// <param name="searchModel">Product search model to add to the manufacturer</param>
        /// <returns>Product list model to add to the manufacturer</returns>
        public virtual async Task <AddProductToManufacturerListModel> PrepareAddProductToManufacturerListModelAsync(AddProductToManufacturerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get products
            var(products, _) = await _productService.SearchProductsAsync(false, showHidden : true,
                                                                         categoryIds : new List <int> {
                searchModel.SearchCategoryId
            },
                                                                         manufacturerId : searchModel.SearchManufacturerId,
                                                                         storeId : searchModel.SearchStoreId,
                                                                         vendorId : searchModel.SearchVendorId,
                                                                         productType : searchModel.SearchProductTypeId > 0?(ProductType?)searchModel.SearchProductTypeId : null,
                                                                         keywords : searchModel.SearchProductName,
                                                                         pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            //prepare grid model
            var model = await new AddProductToManufacturerListModel().PrepareToGridAsync(searchModel, products, () =>
            {
                return(products.SelectAwait(async product =>
                {
                    var productModel = product.ToModel <ProductModel>();

                    productModel.SeName = await _urlRecordService.GetSeNameAsync(product, 0, true, false);

                    return productModel;
                }));
            });

            return(model);
        }