public static List <Sach> GetListNoiBat_XemThem() { List <SachBanChay> listBanChay = new List <SachBanChay>(); foreach (var item in db.Sach.Where(i => i.flag == false).ToList()) { SachBanChay sbc = new SachBanChay(); sbc.MaSach = item.MaSach; sbc.SoLuong = 0; foreach (var item1 in db.ChiTietHoaDon.Where(i => i.flag == true).ToList()) { if (item1.MaSach == sbc.MaSach) { sbc.SoLuong = sbc.SoLuong + item1.SoLuong; } } if (sbc.SoLuong > 0) { listBanChay.Add(sbc); } } List <Sach> listSach = new List <Sach>(); listBanChay = listBanChay.OrderByDescending(i => i.SoLuong).ToList(); foreach (var item in listBanChay) { listSach.Add(db.Sach.Find(item.MaSach)); } return(listSach); }
public List <Sach> SachGetListBanChay() { var db = new BookContext(); List <Sach> sach = new List <Sach>(); List <SachBanChay> banChay = new List <SachBanChay>(); List <HoaDon> listHD = db.HoaDon.Where(i => i.DaThanhToan == true).ToList(); List <ChiTietHoaDon> listCTHD = new List <ChiTietHoaDon>(); foreach (var item in listHD) { foreach (var item1 in db.ChiTietHoaDon.ToList()) { if (item.MaDonHang == item1.MaDonHang) { listCTHD.Add(item1); } } } foreach (var item in db.Sach.Where(i => i.flag == false).ToList()) { SachBanChay a = new SachBanChay(); a.MaSach = item.MaSach; foreach (var item1 in listCTHD.Where(i => i.MaSach == item.MaSach).ToList()) { a.SoLuong = a.SoLuong + item1.SoLuong; } if (a.SoLuong != 0) { banChay.Add(a); } } banChay = banChay.OrderByDescending(i => i.SoLuong).Take(4).ToList(); if (banChay.Count() != 0) { foreach (var item in banChay) { sach.Add(db.Sach.Find(item.MaSach)); } } return(sach); }
//Tac gia noi bat public static List <SachBanChay> GetTacGias() { var db = new BookContext(); var listTacGia = new List <SachBanChay>(); foreach (var item in db.TacGia.Where(x => x.flag == false).ToList()) { SachBanChay s = new SachBanChay(); s.MaSach = item.MaTacGia; s.SoLuong = 0; foreach (var item2 in db.ChiTietHoaDon.Where(x => x.flag == true).ToList()) { if (db.Sach.Find(item2.MaSach).MaTacGia == item.MaTacGia) { s.SoLuong += item2.SoLuong; } } if (s.SoLuong > 0) { listTacGia.Add(s); } } return(listTacGia.OrderByDescending(x => x.SoLuong).Take(6).ToList()); }