public ActionResult DatTour(Chi_Tiet_Hoa_Don hd) { LoadDefaulData(); int tourid = (int)Session["TourId"]; Tour tour = db.Tours.Find(tourid); if (ModelState.IsValid) { if (hd.SoLuong <= (tour.So_Luong_Tham_Gia - tour.So_Luong_Da_Tham_Gia)) { if (hd.SoLuong > 0) { try { hd.Ngay_Lap = DateTime.Parse(DateTime.Now.ToShortDateString()); hd.Tong_Don_Gia = hd.SoLuong * tour.Gia; hd.Tour_Id = tourid; hd.Trang_Thai = "Chờ"; tour.So_Luong_Da_Tham_Gia = tour.So_Luong_Da_Tham_Gia + hd.SoLuong; db.Chi_Tiet_Hoa_Dons.Add(hd); db.Entry(tour).State = EntityState.Modified; db.SaveChanges(); Chi_Tiet_Hoa_Don ct = getChiTietHoaDon(hd.Ten_Khach_Hang, hd.Email, hd.Ngay_Lap); Session["hoadonsendmail"] = ct; string to = hd.Email.Trim(); Session["thongbao"] = "Kiểm tra email của bạn để xác nhận đơn hàng"; Session["Ma"] = randomMa(); string bodysendmail = "Mã xác nhận của bạn là: " + Session["Ma"].ToString() + "<br/><table class='table'><tr><th>Mã hóa đơn</th><th>Ngày lập</th><th>Đơn giá</th><th>Người lập đơn hàng</th></tr><tr><td>" + ct.Id + "</td><td>" + ct.Ngay_Lap + "</td><td>" + ct.Tong_Don_Gia + "</td><td>" + ct.Ten_Khach_Hang + "</td></tr></table>"; sendMail(to, "Đặt tour từ Easy tour booking", bodysendmail); SetDataTour(tour); return(RedirectToAction("XacNhan")); } catch (Exception) { return(HttpNotFound()); } } else { ViewBag.ThongBao = "Số lượng phải >=0"; SetDataTour(tour); return(View()); } } else { ViewBag.ThongBao = "Số lượng không hợp lệ"; SetDataTour(tour); return(View()); } } SetDataTour(tour); return(View()); }
public ActionResult XacNhan(string xacnhan) { LoadDefaulData(); if (xacnhan != "") { string ma = (string)Session["Ma"]; if (xacnhan.Equals(ma.Trim())) { if (Session["loaixacnhan"].ToString().Equals("resetmk")) { string email = (string)Session["emailreset"]; Tai_Khoan tk = db.Tai_Khoans.Where(x => x.Email.Equals(email)).FirstOrDefault(); tk.Mat_Khau = MD5Hash("12345678"); db.Entry(tk).State = EntityState.Modified; db.SaveChanges(); Session["thongbaoreset"] = "Mật khẩu mới của bạn là: 12345678"; return(RedirectToAction("DangNhap")); } if (Session["loaixacnhan"].ToString().Equals("dattour")) { Chi_Tiet_Hoa_Don hd = (Chi_Tiet_Hoa_Don)Session["hoadonsendmail"]; Chi_Tiet_Hoa_Don ct = db.Chi_Tiet_Hoa_Dons.Find(hd.Id); ct.Trang_Thai = "Xác nhận"; db.Entry(ct).State = EntityState.Modified; db.SaveChanges(); ViewBag.ThongBao = "Xác nhận đơn hàng thành công"; string body = "Đơn hàng đã được xác nhận. Nếu có bất kỳ sự thay đổi nào vui lòng liên lệ Hotline (0397611751) để được hỏ trợ"; string subject = "Xác nhận đơn hàng từ Easy tour booking"; sendMail(ct.Email, subject, body); return(RedirectToAction("Index")); } } else { Session["thongbao"] = ""; ViewBag.ThongBao = "Mã xác nhận không đúng"; return(View()); } } Session["thongbao"] = ""; ViewBag.ThongBao = "Bạn chưa nhập mã xác nhận"; return(View()); }
public ActionResult EditHoaDon(int?id) { if ((bool)Session["adminlogin"] == false) { return(RedirectToAction("DangNhap", "TaiKhoan")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Chi_Tiet_Hoa_Don hd = db.Chi_Tiet_Hoa_Dons.Find(id); Session["hoadonhientai"] = hd; if (hd == null) { return(HttpNotFound()); } setDataDropEditHoaDon(); return(View(hd)); }
public ActionResult EditHoaDon(Chi_Tiet_Hoa_Don hd) { setDataDropEditHoaDon(); if (ModelState.IsValid) { Tour tour = getTour(hd.Tour_Id); Chi_Tiet_Hoa_Don hdcu = (Chi_Tiet_Hoa_Don)Session["hoadonhientai"]; int slcu = hdcu.SoLuong; int sldathamgia = tour.So_Luong_Da_Tham_Gia; int soluong = hd.SoLuong; int slchophep = tour.So_Luong_Tham_Gia - tour.So_Luong_Da_Tham_Gia; if (soluong > slchophep) { ViewBag.ThongBao = "Số lượng gnuoiwf tham gia vượt mức co phép"; return(View(hd)); } else { tour.So_Luong_Da_Tham_Gia = sldathamgia - slcu; db.Entry(tour).State = EntityState.Modified; db.SaveChanges(); tour.So_Luong_Da_Tham_Gia = tour.So_Luong_Da_Tham_Gia + hd.SoLuong; db.Entry(tour).State = EntityState.Modified; hd.Ngay_Lap = hdcu.Ngay_Lap; hd.Tong_Don_Gia = hd.SoLuong * tour.Gia; db.Entry(hd).State = EntityState.Modified; db.SaveChanges(); string to = hd.Email.Trim(); Session["thongbao"] = "Kiểm tra email của bạn để xác nhận đơn hàng"; string bodysendmail = "<br/><table class='table'><tr><th>Mã hóa đơn</th><th>Ngày lập</th><th>Đơn giá</th><th>Người lập đơn hàng</th></tr><tr><td>" + hd.Id + "</td><td>" + hd.Ngay_Lap + "</td><td>" + hd.Tong_Don_Gia + "</td><td>" + hd.Ten_Khach_Hang + "</td></tr></table>"; sendMail(to, "Thay đổi đơn hàng từ Easy tour booking", bodysendmail); return(RedirectToAction("QLHoaDon")); } } return(View(hd)); }
private Chi_Tiet_Hoa_Don getChiTietHoaDon(string ten, string email, DateTime ngay) { Chi_Tiet_Hoa_Don hd = db.Chi_Tiet_Hoa_Dons.Where(x => x.Ngay_Lap.Equals(ngay) && x.Ten_Khach_Hang.Equals(ten) && x.Email.Equals(email)).FirstOrDefault(); return(hd); }