//
        // GET: /Booking/Delete/5

        public ActionResult Delete(int booking)
        {
            ViewBag.Message = "Delete booking";
            PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();

            return(View(FindBooking(trip, booking)));
        }
        //
        // GET: /Booking/

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome!";
            PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();

            return(View(trip.TentativeBookings.ToList()));
        }
 public ActionResult Delete(int booking, FormCollection collection)
 {
     try
     {
         PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();
         trip.TentativeBookings.Remove(FindBooking(trip, booking));
         Session["trip"] = trip;
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(booking));
     }
 }
 public ActionResult CreateBooking(string hotelName, BookingConstraints constraints, string guest)
 {
     try
     {
         Booking     b    = bk.CreateBooking(hotelName, constraints, guest);
         PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();
         trip.TentativeBookings.Add(b);
         Session["trip"] = trip;
         return(RedirectToAction("Index"));
     }
     catch (Exception e)
     {
         ModelState.AddModelError(String.Empty, e.Message);
         return(View());
     }
 }
 //
 // GET: /Booking/Finalize
 public ActionResult Finalize()
 {
     try
     {
         ViewBag.Message = "The following bookings have been finalized:";
         PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();
         if (trip.TentativeBookings.Count() == 0)
         {
             throw new BookingException("There are no tentative bookings to finalize.");
         }
         ICollection <Booking> finalized = bk.FinalizeBookings(trip.TentativeBookings);
         trip.TentativeBookings.Clear();
         Session["trip"] = new PlannedTrip();
         return(View(finalized));
     }
     catch (Exception e)
     {
         ModelState.AddModelError(String.Empty, e.Message);
         return(View());
     }
 }
 private Booking FindBooking(PlannedTrip trip, int hashcode)
 {
     return((from booking in trip.TentativeBookings
             where booking.GetHashCode() == hashcode
             select booking).First());
 }
 //
 // GET: /Booking/Finalize
 public ActionResult Finalize()
 {
     try
     {
         ViewBag.Message = "The following bookings have been finalized:";
         PlannedTrip trip = Session["trip"] as PlannedTrip ?? new PlannedTrip();
         if (trip.TentativeBookings.Count() == 0)
             throw new BookingException("There are no tentative bookings to finalize.");
         ICollection<Booking> finalized = bk.FinalizeBookings(trip.TentativeBookings);
         trip.TentativeBookings.Clear();
         Session["trip"] = new PlannedTrip();
         return View(finalized);
     }
     catch (Exception e)
     {
         ModelState.AddModelError(String.Empty, e.Message);
         return View();
     }
 }
 private Booking FindBooking(PlannedTrip trip, int hashcode)
 {
     return (from booking in trip.TentativeBookings
             where booking.GetHashCode() == hashcode
             select booking).First();
 }