public ActionResult Buy(string phone, string name) { // lưu bảng bill -> idbill BillDao dao = new BillDao(); Bill bill = new Bill(); bill.username = name; bill.iduser = phone; int id = dao.Add(bill); ShoppingCart cart = (ShoppingCart)Session["cart"]; if (cart != null) { List <ItemCart> ListCart = cart.ListItem; List <BilDetail> ls = new List <BilDetail>(); for (int i = 0; i < ListCart.Count; i++) { BilDetail billdetail = new BilDetail(); billdetail.idbill = idbill; billdetail.idproduct = idproduct; billdetail.quantity = ListCart[i].quantity; billdetail.prict = (decimal)ListCart[i].price; ls.Add(billdetail); // lưu bảng billandProduct dao.addBillDetai(ls); } } Session["cart"] = null; return(View()); }