public virtual IActionResult ProductList(ManufacturerProductSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageManufacturers)) { return(AccessDeniedKendoGridJson()); } //try to get a manufacturer with the specified id var manufacturer = _manufacturerService.GetManufacturerById(searchModel.ManufacturerId) ?? throw new ArgumentException("No manufacturer found with the specified id"); //prepare model var model = _manufacturerModelFactory.PrepareManufacturerProductListModel(searchModel, manufacturer); return(Json(model)); }
public virtual async Task <IActionResult> ProductList(ManufacturerProductSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageManufacturers)) { return(await AccessDeniedDataTablesJson()); } //try to get a manufacturer with the specified id var manufacturer = await _manufacturerService.GetManufacturerByIdAsync(searchModel.ManufacturerId) ?? throw new ArgumentException("No manufacturer found with the specified id"); //prepare model var model = await _manufacturerModelFactory.PrepareManufacturerProductListModelAsync(searchModel, manufacturer); return(Json(model)); }
/// <summary> /// Prepare manufacturer product search model /// </summary> /// <param name="searchModel">Manufacturer product search model</param> /// <param name="manufacturer">Manufacturer</param> /// <returns>Manufacturer product search model</returns> protected virtual ManufacturerProductSearchModel PrepareManufacturerProductSearchModel(ManufacturerProductSearchModel searchModel, Manufacturer manufacturer) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (manufacturer == null) { throw new ArgumentNullException(nameof(manufacturer)); } searchModel.ManufacturerId = manufacturer.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <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); }
/// <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 async Task <ManufacturerProductListModel> PrepareManufacturerProductListModelAsync(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 = await _manufacturerService.GetProductManufacturersByManufacturerIdAsync(showHidden : true, manufacturerId : manufacturer.Id, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare grid model var model = await new ManufacturerProductListModel().PrepareToGridAsync(searchModel, productManufacturers, () => { return(productManufacturers.SelectAwait(async productManufacturer => { //fill in model values from the entity var manufacturerProductModel = productManufacturer.ToModel <ManufacturerProductModel>(); //fill in additional values (not existing in the entity) manufacturerProductModel.ProductName = (await _productService.GetProductByIdAsync(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 { Data = 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); }), Total = productManufacturers.TotalCount }; return(model); }