public List <SearchProduct_Result> GetProductSearch(int BlockNumber, int BlockSize, int?CategoryID = 0, string ProducName = "", string Order = "") { //var products = ProductManager.GetProduct(1, BlockSize); List <SearchProduct_Result> productlist = new List <SearchProduct_Result>(); Category category = null; int startIndex = (BlockNumber - 1) * BlockSize; List <int> lstcateID = new List <int>(); if (CategoryID != 0) { var categorylist = _db.Categories.Where(m => m.IsDeleted == null || m.IsDeleted == false).ToList(); var cateRoot = categorylist.Where(x => x.ParentCategoryID == 0).ToList(); foreach (var cate in categorylist) { if (cate.ID == CategoryID) { category = cate; break; } } //neu ton tai category thi get list danh sach san pham theo category if (category != null) { lstcateID = GetListChild(category.ID).Select(x => x.ID).ToList(); } } string listCategoryStr = string.Join(",", lstcateID); List <SqlParameter> lstParas = new List <SqlParameter>(); SqlParameter para1 = new SqlParameter(); para1.ParameterName = "CategoryID"; para1.Value = listCategoryStr; lstParas.Add(para1); SqlParameter paraBlockNumber = new SqlParameter(); paraBlockNumber.ParameterName = "PageNum"; paraBlockNumber.Value = BlockNumber; lstParas.Add(paraBlockNumber); SqlParameter paraBlockSize = new SqlParameter(); paraBlockSize.ParameterName = "PageSize"; paraBlockSize.Value = BlockSize; lstParas.Add(paraBlockSize); SqlParameter paraOrder = new SqlParameter(); paraOrder.ParameterName = "OrderBy"; paraOrder.Value = Order; lstParas.Add(paraOrder); SqlParameter paraProducName = new SqlParameter(); paraProducName.ParameterName = "TenSP"; paraProducName.Value = ProducName; lstParas.Add(paraProducName); var storeName = "SearchProduct"; var dt = GetDataTableByStore(storeName, lstParas.ToArray()); List <SearchProduct_Result> dataResult = new List <SearchProduct_Result>(); dataResult = MyTool.ConvertDataTable <SearchProduct_Result>(dt); return(dataResult); }