public bool UpdateTourBooking(TourBooking booking) { try { var t = (from TourBooking in data.TourBookings where TourBooking.MaDatTour == booking.MaDatTour select TourBooking).Single(); t.MaDatTour = booking.MaDatTour; t.MaKH = booking.MaKH; t.MaTour = booking.MaTour; t.DonGia = booking.DonGia; t.SoLuong = booking.SoLuong; t.ThanhTien = booking.ThanhTien; t.DatThanhToan = booking.DatThanhToan; t.Tour = booking.Tour; t.Customer = booking.Customer; data.SubmitChanges(); return(true); } catch { return(false); } }
public ActionResult DeleteConfirmed(int id) { TourBooking tourBooking = db.TourBookings.Find(id); db.TourBookings.Remove(tourBooking); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "MaDatTour,MaKH,MaTour,Dongia,SoLuong,ThanhTien,TrangThai")] TourBooking tourBooking) { if (ModelState.IsValid) { db.Entry(tourBooking).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaKH = new SelectList(db.Customers, "MaKH", "TenKH", tourBooking.MaKH); ViewBag.MaTour = new SelectList(db.Tours, "MaTour", "TenTour", tourBooking.MaTour); return(View(tourBooking)); }
public bool AddTourBooking(TourBooking booking) { try { data.TourBookings.InsertOnSubmit(booking); data.SubmitChanges(); return(true); } catch { return(false); } }
// GET: TourBookings/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TourBooking tourBooking = db.TourBookings.Find(id); if (tourBooking == null) { return(HttpNotFound()); } return(View(tourBooking)); }
public bool DeleteTourBooking(int id) { try { TourBooking tourB = (from TourBooking in data.TourBookings where TourBooking.MaDatTour == id select TourBooking).Single(); data.TourBookings.DeleteOnSubmit(tourB); return(true); } catch { return(false); } }
// GET: TourBookings/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TourBooking tourBooking = db.TourBookings.Find(id); if (tourBooking == null) { return(HttpNotFound()); } ViewBag.MaKH = new SelectList(db.Customers, "MaKH", "TenKH", tourBooking.MaKH); ViewBag.MaTour = new SelectList(db.Tours, "MaTour", "TenTour", tourBooking.MaTour); return(View(tourBooking)); }
//TourOrderService в конструкторе принимает объект IUnitOfWork, через который идет взаимодействие с уровнем DAL. public void MakeOrder(TourOrderDTO orderDTO) { Tour tour = Database.Tours.GetByID(orderDTO.TourId); if (tour == null) { throw new ValidationException("Выбраный тур не найден", ""); } TourBooking order = new TourBooking { TourId = orderDTO.TourId, Date = DateTime.Now, Email = orderDTO.Email, Sum = tour.Price }; Database.TourOrders.Insert(order); Database.Save(); }
public ActionResult BookTour(int?eventId) { if (eventId != null) { //Create Viewmodel TourBooking booking = new TourBooking(); booking.RegularTickets = 1; booking.Events = historicRepository.GetAllTours(); booking.TourName = historicRepository.GetTour((int)eventId).EventName; //Pass ID value of tour: booking.EventId = (int)eventId; return(PartialView("BookTour", booking)); } else { return(RedirectToAction("Index")); } }
public ActionResult BookTour(TourBooking booking) { // The 'booking'-parameter is filled up only with data that is being entered in the form HistoricEvent historicEvent = historicRepository.GetTour(booking.EventId); if (ModelState.IsValid) { List <Ticket> tickets = new List <Ticket>(); Ticket ticket = new Ticket(); //Checks Input Tickets against database Current Tickets int ticketsLeft = historicEvent.CurrentTickets - booking.RegularTickets; int ticketsLeftFamily = historicEvent.CurrentTickets - (booking.RegularTickets * 4); // Fills ticket if its not a family ticket and you have a correct value that isnt more than the available tickets for event if ((!booking.FamilyTicket) && (booking.RegularTickets > 0) && (ticketsLeft >= 0)) { ticket.Amount = booking.RegularTickets; ticket.EventId = booking.EventId; ticket.Event = eventRepository.GetEvent(ticket.EventId); ticket.Price = (booking.RegularTickets * historicEvent.Price); } // Redirects back to index page if ticket input is 0 or less else if ((!booking.FamilyTicket) && (booking.RegularTickets < 1)) { return(RedirectToAction("Index")); } // Redirects back to index page if ticket input is 0 or less else if ((booking.FamilyTicket) && (booking.RegularTickets < 1)) { return(RedirectToAction("Index")); } // Fills ticket if its a family ticket and you have a correct value that isnt more than the available tickets for event else if ((booking.FamilyTicket) && (booking.RegularTickets > 0) && (ticketsLeftFamily >= 0)) { ticket.Amount = (booking.RegularTickets * 4); ticket.EventId = booking.EventId; ticket.Event = eventRepository.GetEvent(ticket.EventId); ticket.Price = (ticket.Amount * historicEvent.FamilyPrice); } // Redirects to index page if ticket input is more than available tickets for event else if ((ticketsLeft < 0) || (ticketsLeftFamily < 0)) { return(RedirectToAction("Index")); } // Create session if it doesn't exist or add ticket to existing session if (Session["currentTickets"] == null) { tickets.Add(ticket); Session["CurrentTickets"] = tickets; } else { List <Ticket> sessionTickets = (List <Ticket>)Session["currentTickets"]; sessionTickets.Add(ticket); } return(RedirectToAction("Index", "Ticket")); } // Post booking return(PartialView("BookTour", booking)); }