public ActionResult deleteDonHang(int id) { CT_DON_HANG dev = db.CT_DON_HANGs.SingleOrDefault(n => n.MaDH == id); DON_DAT_HANG don = db.DON_DAT_HANGs.SingleOrDefault(n => n.MaDH == id); if (dev == null || don == null) { Response.StatusCode = 404; return(null); } try { db.CT_DON_HANGs.DeleteOnSubmit(dev); db.DON_DAT_HANGs.DeleteOnSubmit(don); } catch (Exception e) { Response.Write(e.Message); } db.SubmitChanges(); return(RedirectToAction("donHang")); }
public ActionResult Dathang(FormCollection collection) { KHACH_HANG kh = (KHACH_HANG)Session["Taikhoan"]; //khach hang da dang nhap //luu cac thong tin //don dat hang //chi tiet don hang //thong tin nguoi nhan DON_DAT_HANG ddh = new DON_DAT_HANG(); if (kh != null) { //luu tru don dat hang List <Giohang> gh = Laygiohang(); ddh.MaKH = kh.MaKH; ddh.NgayDH = DateTime.Now; var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]); ddh.NgayGiao = DateTime.Parse(ngaygiao); ddh.TinhTrangGiaoHang = false; ddh.DaThanhToan = false; ddh.Name = collection["name"]; ddh.Phone = collection["phone"]; ddh.Address = collection["address"]; ddh.Email = collection["email"]; db.DON_DAT_HANGs.InsertOnSubmit(ddh); db.SubmitChanges(); int temp = db.DON_DAT_HANGs.ToList().Last().MaDH; //Them chi tiet don hang foreach (var item in gh) { CT_DON_HANG ctdh = new CT_DON_HANG(); ctdh.MaDH = temp; ctdh.MaDevice = item.iMasach; ctdh.SoLuong = item.iSoluong; ctdh.DonGia = (decimal)item.dDongia; db.CT_DON_HANGs.InsertOnSubmit(ctdh); } db.SubmitChanges(); //ke ca co dang nhap va khong dang nhap } //neu khong dang nhap //luu thong tin dia chi nguoi nhan //don dat hang else { Response.Write("<script>alert('that bai')</script>"); } return(RedirectToAction("Xacnhandonhang", "Giohang", new { sdt = ddh.Phone })); }
public ActionResult checkOut(FormCollection collection) { //khach hang da dang nhap //luu cac thong tin //don dat hang //chi tiet don hang //thong tin nguoi nhan DON_DAT_HANG ddh = new DON_DAT_HANG(); List <Giohang> gh = Laygiohang(); ddh.MaKH = 2; ddh.NgayDH = DateTime.Now; var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]); ddh.NgayGiao = DateTime.Parse(ngaygiao); ddh.TinhTrangGiaoHang = false; ddh.DaThanhToan = false; ddh.Name = collection["name"]; ddh.Phone = collection["phone"]; ddh.Address = collection["address"]; ddh.Email = collection["email"]; db.DON_DAT_HANGs.InsertOnSubmit(ddh); db.SubmitChanges(); //Them chi tiet don hang foreach (var item in gh) { CT_DON_HANG ctdh = new CT_DON_HANG(); int temp = db.DON_DAT_HANGs.ToList().Last().MaDH; ctdh.MaDH = ddh.MaDH; ctdh.MaDevice = item.iMasach; ctdh.SoLuong = item.iSoluong; ctdh.DonGia = (decimal)item.dDongia; db.CT_DON_HANGs.InsertOnSubmit(ctdh); } //ke ca co dang nhap va khong dang nhap try { db.SubmitChanges(); Session["Giohang"] = null; } catch (Exception) { } return(RedirectToAction("Xacnhandonhang", "Giohang", new { email = ddh.Email })); }