/// <summary> /// Prepare paged manufacturer product list model /// </summary> /// <param name="searchModel">Manufacturer product search model</param> /// <param name="manufacturer">Manufacturer</param> /// <returns>Manufacturer product list model</returns> public virtual ManufacturerProductListModel PrepareManufacturerProductListModel(ManufacturerProductSearchModel searchModel, Manufacturer manufacturer) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (manufacturer == null) { throw new ArgumentNullException(nameof(manufacturer)); } //get product manufacturers var productManufacturers = _manufacturerService.GetProductManufacturersByManufacturerId(showHidden: true, manufacturerId: manufacturer.Id, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare grid model var model = new ManufacturerProductListModel().PrepareToGrid(searchModel, productManufacturers, () => { return(productManufacturers.Select(productManufacturer => { //fill in model values from the entity var manufacturerProductModel = productManufacturer.ToModel <ManufacturerProductModel>(); //fill in additional values (not existing in the entity) manufacturerProductModel.ProductName = _productService.GetProductById(productManufacturer.ProductId)?.Name; return manufacturerProductModel; })); }); return(model); }
/// <summary> /// Prepare paged manufacturer product list model /// </summary> /// <param name="searchModel">Manufacturer product search model</param> /// <param name="manufacturer">Manufacturer</param> /// <returns>Manufacturer product list model</returns> public virtual ManufacturerProductListModel PrepareManufacturerProductListModel(ManufacturerProductSearchModel searchModel, Manufacturer manufacturer) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (manufacturer == null) { throw new ArgumentNullException(nameof(manufacturer)); } //get product manufacturers var productManufacturers = _manufacturerService.GetProductManufacturersByManufacturerId(showHidden: true, manufacturerId: manufacturer.Id, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare grid model var model = new ManufacturerProductListModel { //fill in model values from the entity Data = productManufacturers.Select(productManufacturer => new ManufacturerProductModel { Id = productManufacturer.Id, ManufacturerId = productManufacturer.ManufacturerId, ProductId = productManufacturer.ProductId, ProductName = _productService.GetProductById(productManufacturer.ProductId)?.Name, IsFeaturedProduct = productManufacturer.IsFeaturedProduct, DisplayOrder = productManufacturer.DisplayOrder }), Total = productManufacturers.TotalCount }; return(model); }