public ActionResult CancelReservedRoom(string roomBookingID) { try { int bookingID = Int32.Parse(roomBookingID); RoomBooking roomBooking = db.RoomBookings.Where(x => x.RoomBookingID.Equals(bookingID)).Single(); if (roomBooking == null) { return(Json(new { Status = false }, JsonRequestBehavior.AllowGet)); } else { SendMailService mailService = new SendMailService(); HashCodeService hashCodeService = new HashCodeService(); String hashCode = hashCodeService.createRoomBookingCancelCode(bookingID, roomBooking.Email); mailService.toAddress = roomBooking.Email; //ND mail gui cho khach hang: mailService.body = "CANCEL ROOM BOOKING INFORMATION\n" + "CustomerName: " + roomBooking.Name + "\n" + "ID: " + roomBooking.RoomBookingID + "\n" + "CheckInDate: " + roomBooking.CheckinDate + "\n" + "CheckOutDate: " + roomBooking.CheckoutDate + "\n" + "Click here to cancel your booking: " + "http://localhost:8080/RoomBookings/DeleteRoomBooking/?id=" + roomBooking.RoomBookingID + "&hash=" + hashCode; mailService.subject = "CANCEL ROOM BOOKING INFORMATION"; mailService.sendMail(); return(Json(new { Status = true }, JsonRequestBehavior.AllowGet)); } } catch { return(Json(new { Status = false }, JsonRequestBehavior.AllowGet)); } }
//GET: RoomBookings/DeleteRoomBooking public ActionResult DeleteRoomBooking(int id, string hash) { RoomBooking roomBooking = db.RoomBookings.Where(x => x.RoomBookingID == id).SingleOrDefault(); if (roomBooking != null) { HashCodeService hashCodeService = new HashCodeService(); hash = hash.Replace(' ', '+'); String hashCode = hashCodeService.createRoomBookingCancelCode(id, roomBooking.Email); if (hash.Equals(hashCode)) { roomBooking.Status = "Canceled"; db.Entry(roomBooking).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Search", "Home")); } } return(RedirectToAction("Index", "Home")); }