public ActionResult Xem(ThongKeHD tk) { using (var db = new BookContext()) { List <HoaDon> listHD = new List <HoaDon>(); listHD = db.HoaDon.Where(i => i.NgayTao.Year == tk.Year).ToList(); if (listHD.Count() == 0) { return(RedirectToAction("Index", "ThongKe")); } else { double Tong = 0; List <ThongKeHD> listTK = new List <ThongKeHD>(); int month = 1; while (month <= 12) { ThongKeHD hd = new ThongKeHD(); hd.Year = tk.Year; hd.Month = month; hd.SoLuongBill = listHD.Where(i => i.NgayTao.Month == month).Count(); foreach (var item in listHD.Where(i => i.NgayTao.Month == month).ToList()) { hd.TongTien += item.TongTien; } Tong = Tong + hd.TongTien; listTK.Add(hd); month++; } ViewBag.Tong = Tong; Session["ThongKe"] = listTK; return(View("Index")); } } }
public ActionResult Xem(ThongKeHD tk) { using (var db = new BookContext()) { return(null); //List<HoaDon> listHD = new List<HoaDon>(); //listHD = db.HoaDon.Where(i => i.NgayTao.Year == tk.Year).ToList(); //if (listHD.Count() == 0) //{ // return RedirectToAction("Index", "ThongKe"); //} //else //{ // double Tong = 0; // List<ThongKeHD> listTK = new List<ThongKeHD>(); // int month = 1; // while (month <= 12) // { // ThongKeHD hd = new ThongKeHD(); // hd.Year = tk.Year; // hd.Month = month; // hd.SoLuongBill = listHD.Where(i => i.NgayTao.Month == month).Count(); // foreach (var item in listHD.Where(i => i.NgayTao.Month == month).ToList()) // { // hd.TongTien += item.TongTien; // } // Tong = Tong + hd.TongTien; // listTK.Add(hd); // month++; // } // ViewBag.Tong = Tong; // Session["ThongKe"] = listTK; // return View("Index"); //} } }