public virtual IActionResult UsedByProducts(ProductAttributeProductSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes))
            {
                return(AccessDeniedKendoGridJson());
            }

            //try to get a product attribute with the specified id
            var productAttribute = _productAttributeService.GetProductAttributeById(searchModel.ProductAttributeId)
                                   ?? throw new ArgumentException("No product attribute found with the specified id");

            //prepare model
            var model = _productAttributeModelFactory.PrepareProductAttributeProductListModel(searchModel, productAttribute);

            return(Json(model));
        }
Exemplo n.º 2
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> UsedByProducts(ProductAttributeProductSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAttributes))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get a product attribute with the specified id
            var productAttribute = await _productAttributeService.GetProductAttributeByIdAsync(searchModel.ProductAttributeId)
                                   ?? throw new ArgumentException("No product attribute found with the specified id");

            //prepare model
            var model = await _productAttributeModelFactory.PrepareProductAttributeProductListModelAsync(searchModel, productAttribute);

            return(Json(model));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepare search model of products that use the product attribute
        /// </summary>
        /// <param name="searchModel">Search model of products that use the product attribute</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <returns>Search model of products that use the product attribute</returns>
        protected virtual ProductAttributeProductSearchModel PrepareProductAttributeProductSearchModel(ProductAttributeProductSearchModel searchModel,
                                                                                                       ProductAttribute productAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (productAttribute == null)
            {
                throw new ArgumentNullException(nameof(productAttribute));
            }

            searchModel.ProductAttributeId = productAttribute.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Prepare paged list model of products that use the product attribute
        /// </summary>
        /// <param name="searchModel">Search model of products that use the product attribute</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <returns>List model of products that use the product attribute</returns>
        public virtual ProductAttributeProductListModel PrepareProductAttributeProductListModel(ProductAttributeProductSearchModel searchModel,
                                                                                                ProductAttribute productAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (productAttribute == null)
            {
                throw new ArgumentNullException(nameof(productAttribute));
            }

            //get products
            var products = _productService.GetProductsByProductAtributeId(productAttributeId: productAttribute.Id,
                                                                          pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new ProductAttributeProductListModel
            {
                //fill in model values from the entity
                Data = products.Select(product => new ProductAttributeProductModel
                {
                    Id          = product.Id,
                    ProductName = product.Name,
                    Published   = product.Published
                }),
                Total = products.TotalCount
            };

            return(model);
        }
        /// <summary>
        /// Prepare paged list model of products that use the product attribute
        /// </summary>
        /// <param name="searchModel">Search model of products that use the product attribute</param>
        /// <param name="productAttribute">Product attribute</param>
        /// <returns>List model of products that use the product attribute</returns>
        public virtual async Task <ProductAttributeProductListModel> PrepareProductAttributeProductListModelAsync(ProductAttributeProductSearchModel searchModel,
                                                                                                                  ProductAttribute productAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (productAttribute == null)
            {
                throw new ArgumentNullException(nameof(productAttribute));
            }

            //get products
            var products = await _productService.GetProductsByProductAtributeIdAsync(productAttributeId : productAttribute.Id,
                                                                                     pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            //prepare list model
            var model = new ProductAttributeProductListModel().PrepareToGrid(searchModel, products, () =>
            {
                //fill in model values from the entity
                return(products.Select(product =>
                {
                    var productAttributeProductModel = product.ToModel <ProductAttributeProductModel>();
                    productAttributeProductModel.ProductName = product.Name;
                    return productAttributeProductModel;
                }));
            });

            return(model);
        }