public ActionResult Details(int id)
        {
            // If a user is logged in, display details. Otherwise, redirect to login
            if (Session["CustomerId"] != null)
            {
                // SQL query
                string query = "SELECT * FROM BookingDetails WHERE BookingId = @p0";
                Models.BookingDetail detail = db.BookingDetails.SqlQuery(query, id).FirstOrDefault();

                return(View(detail));
            }
            else
            {
                return(RedirectToAction("Login", "Customer"));
            }
        }
        public ActionResult ConfirmPurchase(int id)
        {
            // If a user is logged in, confirm purchase. Otherwise, redirect to login
            if (Session["CustomerId"] != null)
            {
                // Get CustomerId
                int custID = Convert.ToInt32(Session["CustomerId"]);
                // Get PackageId
                int pkgID = id;
                // Select package with given ID to create booking
                Models.Package pkg = db.Packages.FirstOrDefault(u => u.PackageId.Equals(pkgID));
                // Insert selected package into Bookings table
                Booking book = new Booking();
                book.BookingDate   = DateTime.Now;                          // BookingDate is the time the booking is made
                book.BookingNo     = RandomStringGenerator.RandomString(6); // creates random string of 6 characters
                book.TravelerCount = 1;                                     // project document specified always 1 traveler, for now
                book.CustomerId    = custID;
                book.TripTypeId    = "B";
                book.PackageId     = pkg.PackageId;
                book.BasePrice     = pkg.PkgBasePrice;

                /* "ItineraryNo" from BookingDetails does not auto-increment, AND allows
                 * duplicate values, so this SQL query will grab the highest ItineraryNo
                 * value, which we can add 1 to to make a new ItineraryNo */
                //string query =
                //    "SELECT TOP 1 ItineraryNo " +
                //    "FROM BookingDetails " +
                //    "ORDER BY ItineraryNo DESC";
                double itinerary = BookingDetailDB.GetLastItineraryNo();
                int    bookingId = BookingDetailDB.GetLastBookingId();

                /* Switch statement that determines the destination of a package, class, and
                 * RegionId of a package. There's nothing in the Packages table showing this,
                 * so the destinations are hardcoded, as well as the potential package IDs.
                 * Ideally, a destination column would be added to the Packages table */
                string destination;
                string region;
                string classID; // first class, business class, etc...

                switch (pkgID)
                {
                case 1:                   // Caribbean
                    destination = "Santo Domingo, Dominican Republic";
                    region      = "OTHR"; // Other region
                    classID     = "ECN";  // Economy Class
                    break;

                case 2:                  // Polynesia
                    destination = "Honolulu, United States";
                    region      = "NA";  // North America
                    classID     = "ECN"; // Economy Class
                    break;

                case 3:     // Asia
                    destination = "Bangkok, Thailand";
                    region      = "ASIA";
                    classID     = "DLX"; // Deluxe Class
                    break;

                case 4:                  // Europe
                    destination = "Rome, Italy";
                    region      = "EU";  // Europe and UK
                    classID     = "FST"; // First Class
                    break;

                default:                  // New packages without any assignment here, or errors
                    destination = "Atlantis";
                    region      = "OTHR"; // Other region
                    classID     = "BSN";  // Business Class
                    break;
                }

                // Create new BookingDetail for this booking
                Models.BookingDetail detail = new Models.BookingDetail();
                detail.ItineraryNo       = itinerary + 1;
                detail.TripStart         = pkg.PkgStartDate;
                detail.TripEnd           = pkg.PkgEndDate;
                detail.Description       = pkg.PkgDesc;
                detail.Destination       = destination;
                detail.BasePrice         = pkg.PkgBasePrice;
                detail.AgencyCommission  = pkg.PkgAgencyCommission;
                detail.BookingId         = bookingId + 1;
                detail.RegionId          = region;
                detail.ClassId           = classID;
                detail.FeeId             = "BK"; // "Booking Charge", hardcoded as no column for this in Packages
                detail.ProductSupplierId = 80;   // "80" corresponds to a company that
                                                 // provides airfare; hardcoded, once again

                try
                {
                    db.Entry(book).State = EntityState.Added;

                    /* Save changes to Bookings before BookingDetails, because of
                     * foreign key depencency for BookingId */
                    db.SaveChanges();
                    db.Entry(detail).State = EntityState.Added;
                    db.SaveChanges();

                    /* Put something in TempData, which is cleared after 1 request, so
                     * success message will only display the first time each package is booked,
                     * rather than every time Dashboard/Index is loaded */
                    TempData["PkgMessage2"] = "Package successfully booked!";
                    return(RedirectToAction("Index", "Dashboard"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                return(RedirectToAction("Login", "Customer"));
            }
        }