//Lay danh sach mon hoc da luu trong cart public ActionResult Cart() { if (AuthorizeUser()) { int idUser = Convert.ToInt32(Session["UserId"]); CartClient CC = new CartClient(); ViewBag.cart = CC.getCartbyUser(idUser); return(View()); } return(Redirect("/Account/Login")); }
//Buy from cart public bool AddListHistory() { if (AuthorizeUser()) { try { int idUser = Convert.ToInt32(Session["UserId"]); CartClient CC = new CartClient(); var list = CC.getCartbyUser(idUser); DateTime time = DateTime.Now; foreach (var item in list) { try { int price = Convert.ToInt32(item.price - (item.price * item.discount / 100)); History history = new History(); history.id_course = item.id_course; history.id_user = item.id_user; history.price = price; history.date = time; db.Histories.Add(history); DeleteCart(history.id_user, history.id_course); db.SaveChanges(); } catch { return(false); } } return(true); } catch { return(false); } } return(false); }