public IActionResult TimKiem(string keyword, int?giatu, int?giaden) { var dsHangHoa = _eStore20Context.HangHoa.Where(hh => hh.TenHh.Contains(keyword)); if (giatu.HasValue) { dsHangHoa = dsHangHoa.Where(hh => hh.DonGia >= giatu); } if (giaden.HasValue) { dsHangHoa = dsHangHoa.Where(p => p.DonGia <= giaden); } var result = dsHangHoa.Select(p => new TimKiemHangHoa { MaHh = p.MaHh, TenHh = p.TenHh, DonGia = p.DonGia.Value, Hinh = MyTools.CheckImageExist(p.Hinh, "HangHoa"), GiamGia = p.GiamGia, NgaySx = p.NgaySx }).ToList(); return(View(result)); }
public IActionResult Index(int?PageCount, string SapXep, int page = 1) { var pageCount = PageCount.HasValue ? PageCount.Value : 20; if (string.IsNullOrEmpty(SapXep)) { SapXep = "TenHh"; } var pageCountSelected = MyTools.Pages.SingleOrDefault(p => p.Value == pageCount); ViewBag.Pages = new SelectList(MyTools.Pages, "Value", "Text", pageCountSelected); var result = _eStore20Context.HangHoa.AsQueryable(); switch (SapXep.ToLower()) { case "tenHh": result = result.OrderBy(p => p.TenHh); break; case "dongia": result = result.OrderBy(p => p.DonGia).ThenBy(p => p.TenHh); break; } var danhsach = result.Select(p => new TimKiemHangHoa { MaHh = p.MaHh, TenHh = p.TenHh, DonGia = p.DonGia.Value, Hinh = MyTools.CheckImageExist(p.Hinh, "HangHoa"), GiamGia = p.GiamGia, NgaySx = p.NgaySx }).Skip((page - 1) * pageCount).Take(pageCount).ToList(); return(View(danhsach)); }
public IActionResult TimKiem(string Keyword, int?GiaTu, int?GiaDen) { var dsHangHoa = _context.HangHoa.Where(hh => hh.TenHh.Contains(Keyword)); if (GiaTu.HasValue) { dsHangHoa = dsHangHoa.Where(hh => hh.DonGia >= GiaTu); } if (GiaDen.HasValue) { dsHangHoa = dsHangHoa.Where(hh => hh.DonGia <= GiaDen); } var result = dsHangHoa.Select(p => new HangHoaViewModel { MaHh = p.MaHh, TenHh = p.TenHh, DonGia = p.DonGia.Value, Hinh = MyTools.CheckImageExist(p.Hinh, "HangHoa"), GiamGia = p.GiamGia, NgaySX = p.NgaySx }).ToList(); return(View(result)); }
public IActionResult Index(int?PageCount, string SapXep, int Page = 1) { var pageCount = PageCount.HasValue ? PageCount.Value : 20; if (!string.IsNullOrEmpty(SapXep)) { SapXep = "TenHh"; } ViewBag.Pager = new SelectList(MyTools.Pages, "Value", "Text", pageCount); var result = _context.HangHoa.Select(p => new HangHoaViewModel { MaHh = p.MaHh, TenHh = p.TenHh, DonGia = p.DonGia.Value, Hinh = MyTools.CheckImageExist(p.Hinh, "HangHoa"), GiamGia = p.GiamGia, NgaySX = p.NgaySx }); switch (SapXep.ToLower()) { case "tenhh": result = result.OrderBy(p => p.TenHh); break; case "dongia": result = result.OrderBy(p => p.DonGia).ThenBy(p => p.TenHh); break; } var danhsach = result.Skip((Page - 1) * pageCount) .Take(pageCount).ToList(); return(View(danhsach)); }
public IActionResult LoadMore(int page = 1) { var result = _context.HangHoa.Skip((page - 1) * so_sp_moi_trang).Take(so_sp_moi_trang).Select(p => new TimKiemHangHoa { MaHh = p.MaHh, TenHh = p.TenHh, DonGia = p.DonGia.Value, Hinh = MyTools.CheckImageExist(p.Hinh, "HangHoa"), GiamGia = p.GiamGia, NgaySx = p.NgaySx }).ToList(); return(PartialView(result)); }