public async Task <IActionResult> ProductSearch(DataSourceRequest command, ProductSearchListModel model) { model.ClientId = (int)_workContext.CurrentCustomer.ClientId; var(productsearchlistmodel, totalCount) = await _selectItemsServices.PrepareProductListModel(model, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = productsearchlistmodel, Total = totalCount }; return(Json(gridModel)); }
public async Task <(IEnumerable <ProductSearchModel> productsearchlistmodel, int totalCount)> PrepareProductListModel(ProductSearchListModel model, int pageIndex = 0, int pageSize = 2147483647) { SqlParameter[] pr = new SqlParameter[] { new SqlParameter("@intClientId", model.ClientId), new SqlParameter("@txtSS", model.SearchProductByName) }; var products = await _dbContext.Set <ItemSearch>().FromSqlRaw("exec ItemSearch @intClientId,@txtSS", pr).ToListAsync(); int totalCount = products.Count; int pageOffSet = (Convert.ToInt32(pageIndex) - 1) * 10; products = products.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList(); ///Add from store procedure response to model var productsearchlistmodel = new List <ProductSearchModel>(); foreach (var p in products) { productsearchlistmodel.Add(new ProductSearchModel { VItemId = p.VItemID, Item = p.Vitem, Mfg = p.MfgNo, Description = p.VDescription, Unit = p.UOM, Pkg = p.Pkg, Price = p.SellingPrice, Vendor = p.VName }); } return(productsearchlistmodel, totalCount); }