public ActionResult ProductHomeCategory(ProductType cate) { try { CreateRepos(); ProductCategoryPageContainer model = new ProductCategoryPageContainer(); List <ProductCategoryPage> mProductPageList = new List <ProductCategoryPage>(); ProductType productCategory = ProductRepos.LayLoaiSanPhamTheoId(cate.ID); if (productCategory != null) { List <ProductType> mProductTypeList = ProductRepos.getProductTypeByProductType(productCategory.ID, 3); if (mProductTypeList.Count > 0) { mProductPageList.AddRange(mProductTypeList.Select(it => ProductHelper.GetCategoryPage(it, 1, true))); } } model.List = mProductPageList; model.ProductType = productCategory; model.Brands = ProductRepos.getRandomBrands(cate.ID, 12); return(View("HomeCategory", model)); } catch (Exception ex) { return(Content(ex.ToString())); } finally { DisposeRepos(); } }
public ActionResult Category(int pGroupId = 0, int pPage = 1) { V308CMSEntities mEntities = new V308CMSEntities(); ProductRepository productRepository = new ProductRepository(mEntities); MarketRepository marketRepository = new MarketRepository(mEntities); ProductCategoryPageContainer mProductCategoryPageContainer = new ProductCategoryPageContainer(); List <ProductCategoryPage> mProductPageList = new List <ProductCategoryPage>(); ProductType mProductType = new ProductType(); List <ProductType> mProductTypeList; List <ProductType> mSoCheList; List <Product> mBestBuyList; List <Product> mProductList = new List <Product>(); try { //lay chi tiet ProductType //lay danh sach các sieu thi co loai san pham nay //lay cac san pham cua nhom do mProductType = productRepository.LayLoaiSanPhamTheoId(pGroupId); if (mProductType != null) { ViewBag.Id = mProductType.ID; ViewBag.Name = mProductType.Name; ViewBag.Level = mProductType.Level; ViewBag.TypeBanner = mProductType.TypeBanner; //lay danh sach sieu thi ban loai san pham nay if (mProductType.Parent == 0) { mProductTypeList = productRepository.getProductTypeByProductType(mProductType.ID);//lay danh sach cap 1 } else { mProductTypeList = new List <ProductType>(); mProductTypeList.Add(mProductType); //mProductTypeList = productRepository.getProductTypeByProductType((int)mProductType.Parent);//lay danh sach cap 2 } //lay các san pham cua nhom nay if (mProductTypeList.Count > 0) { foreach (ProductType it in mProductTypeList) { //Chi tiết market ProductCategoryPage mProductPage = new ProductCategoryPage(); mProductPage.Name = it.Name; mProductPage.Id = (int)it.ID; mProductPage.Image = it.Image; if (mProductType.Parent == 0) { mProductList = productRepository.LayTheoTrangAndType(1, 4, it.ID, it.Level); } else { mProductList = productRepository.LayTheoTrangAndType(1, 40, it.ID, it.Level); } mProductPage.List = mProductList; mProductPageList.Add(mProductPage); } } else { ProductCategoryPage mProductPage = new ProductCategoryPage(); mProductPage.Name = mProductType.Name; mProductPage.Id = (int)mProductType.ID; mProductPage.Image = mProductType.Image; mProductList = productRepository.LayTheoTrangAndType(1, 40, mProductType.ID, mProductType.Level); mProductPage.List = mProductList; mProductPageList.Add(mProductPage); } //lay danh sach cac nhom so che mSoCheList = productRepository.LayProductTypeTheoParentId(147); mProductCategoryPageContainer.ProductTypeList = mSoCheList; //lay cac san pham ban chay mBestBuyList = productRepository.getBestBuyWithType(1, 10, 147, "10030"); mProductCategoryPageContainer.ProductList = mBestBuyList; } mProductCategoryPageContainer.List = mProductPageList; mProductCategoryPageContainer.ProductType = mProductType; if (mProductList.Count < 40) { mProductCategoryPageContainer.IsEnd = true; } mProductCategoryPageContainer.Page = pPage; //lay chi tiet san pham if (!Request.Browser.IsMobileDevice) { return(View(mProductCategoryPageContainer)); } else { return(View("~/Views/Home/MobileCategory.cshtml", mProductCategoryPageContainer)); } } catch (Exception ex) { return(Content(ex.InnerException.ToString())); } finally { mEntities.Dispose(); productRepository.Dispose(); } }
public ActionResult Category(int pGroupId = 0) { try { CreateRepos(); ProductCategoryPageContainer model = new ProductCategoryPageContainer(); int nPage = Convert.ToInt32(Request.QueryString["p"]); if (nPage < 1) { nPage = 1; } List <Product> mProductList = new List <Product>(); List <ProductCategoryPage> mProductPageList = new List <ProductCategoryPage>(); List <ProductType> mProductTypeList; ProductType ProductCategory = ProductRepos.LayLoaiSanPhamTheoId(pGroupId); if (ProductCategory != null) { CategoryPage CategoryPage = ProductHelper.getProductsByCategory(ProductCategory.ID, nPage); model.Products = CategoryPage.Products; model.ProductTotal = CategoryPage.ProductTotal; model.Brands = ProductRepos.getRandomBrands(ProductCategory.ID, 6); if (ProductCategory.Parent == 0) { mProductTypeList = ProductRepos.getProductTypeByProductType(ProductCategory.ID);//lay danh sach cap 1 } else { mProductTypeList = new List <ProductType>(); mProductTypeList.Add(ProductCategory); //mProductTypeList = productRepository.getProductTypeByProductType((int)mProductType.Parent);//lay danh sach cap 2 } if (mProductTypeList.Count > 0) { foreach (ProductType it in mProductTypeList) { mProductPageList.Add(ProductHelper.GetCategoryPage(it, nPage)); } } else { mProductPageList.Add(ProductHelper.GetCategoryPage(ProductCategory, nPage)); } //lay danh sach cac nhom so che //mSoCheList = productRepos.LayProductTypeTheoParentId(147); //Model.ProductTypeList = mSoCheList; //lay cac san pham ban chay //mBestBuyList = productRepos.getBestBuyWithType(1, 10, 147, "10030"); //Model.ProductList = mBestBuyList; } model.List = mProductPageList; model.ProductType = ProductCategory; model.BestSeller = ProductRepos.getProductsRandom(); //if (mProductList.Count < 40) // Model.IsEnd = true; model.Page = nPage; return(View("Category", model)); //if (!Request.Browser.IsMobileDevice) // return View("Category", model); //else // return View("MobileCategory", model); } catch (Exception ex) { return(Content(ex.ToString())); } }