public ActionResult DatHang(FormCollection collection) { DATHANG dh = new DATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <Giohang> gh = Laygiohang(); try { dh.NGAYLAP = DateTime.Now; dh.MAKH = kh.MAKH; dblayer.add_dh(dh); foreach (var item in gh) { CTDH ctdh = new CTDH(); ctdh.MADH = "1"; ctdh.MAHANGHOA = item.iMAHANGHOA; ctdh.SOLUONG = item.iSOLUONG; ctdh.DONGIA = (decimal)item.dDONGIABAN; ctdh.THANHTIEN = (decimal)item.dTHANHTIEN; dblayer.add_ctdh(ctdh); } } catch (Exception ex) { @ViewBag.Error = ex.Message; return(this.DatHang()); } Session["Giohang"] = null; return(RedirectToAction("Xacnhandonhang", "Giohang")); }