public async Task <IActionResult> OnGetAsync(string categoryCode, string brandCode) { ProductBrandList = await _catalogServcie.GetCatalogBrand(); ProductCategoryList = await _catalogServcie.GetCatalogCategory(); var productList = await _catalogServcie.GetCatalog(); // filter products by brand if (!string.IsNullOrWhiteSpace(brandCode)) { ProductList = productList.Where(p => p.BrandCode == brandCode); } // filter products by category if (!string.IsNullOrWhiteSpace(categoryCode)) { ProductList = productList.Where(p => string.Equals(p.ParentCategoryCode, categoryCode) || string.Equals(p.ChildCategoryCode, categoryCode)); } if (string.IsNullOrWhiteSpace(brandCode) && string.IsNullOrWhiteSpace(categoryCode)) { ProductList = productList; } ProductBrandList = ProductBrandList.Select(x => { x.ProductCount = ProductList.Where(p => p.BrandCode == x.Code).Count(); return(x); }); ProductBrandList = ProductBrandList.Where(x => x.ProductCount > 0).ToList(); ProductCategoryList = ProductCategoryList.Select(x => { x.ProductCount = ProductList.Where(p => p.ParentCategoryCode == x.Code).Count(); return(x); }); ProductCategoryList = ProductCategoryList.Where(x => x.ProductCount > 0).ToList(); PagedCatalog = ProductList.Skip((PageIndex - 1) * PageSize) .Take(PageSize).OrderBy(x => x.Name).ToList(); TotalItems = ProductList.Count(); return(Page()); }
public static ProductBrandList GetEditProductBrandData(string id, int index) { // Set active row HttpContext.Current.Session["ROW_ID"] = id; HttpContext.Current.Session["ROW"] = index; var productBrandData = new ProductBrandList(); var dsDataProductBrand = new DataSet(); try { using (SqlConnection conn = new SqlConnection(SPlanetUtil.GetConnectionString())) { List <SqlParameter> arrParm = new List <SqlParameter> { new SqlParameter("@search_name", SqlDbType.VarChar, 200) { Value = "" }, new SqlParameter("@id", SqlDbType.Int) { Value = Convert.ToInt32(id) } }; conn.Open(); dsDataProductBrand = SqlHelper.ExecuteDataset(conn, "sp_product_brand_list", arrParm.ToArray()); conn.Close(); } if (dsDataProductBrand.Tables.Count > 0) { var row = dsDataProductBrand.Tables[0].Rows[0]; productBrandData.id = Convert.IsDBNull(row["id"]) ? 0 : Convert.ToInt32(row["id"]); productBrandData.brand_code = Convert.IsDBNull(row["brand_code"]) ? null : Convert.ToString(row["brand_code"]); productBrandData.brand_name_eng = Convert.IsDBNull(row["brand_name_tha"]) ? null : Convert.ToString(row["brand_name_tha"]); productBrandData.brand_name_tha = Convert.IsDBNull(row["brand_name_eng"]) ? null : Convert.ToString(row["brand_name_eng"]); } } catch (Exception ex) { throw ex; } return(productBrandData); }