/// <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); }