Esempio n. 1
0
        // GET: Reservations/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(View("Error", new String[] { "Please specify a reservation to view!" }));
            }

            //update this statement to have an include clause to get the reservation details and ticket info
            Models.Business.Reservation reservation = await _context.Reservations
                                                      .Include(r => r.Tickets)
                                                      .ThenInclude(r => r.Flight)
                                                      .ThenInclude(r => r.FlightInfo)
                                                      .Include(r => r.Customer)
                                                      .FirstOrDefaultAsync(m => m.ReservationID == id);

            if (reservation == null) //reservation not found
            {
                return(View("Error", new String[] { "Cannot find this reservation!" }));
            }

            if (User.IsInRole("Manager") == false && User.IsInRole("Agent") == false && reservation.Customer.UserName != User.Identity.Name) //they are trying to see something that isn't theirs
            {
                return(View("Error", new String[] { "Unauthorized: You are attempting to view another customer's reservation!" }));
            }

            return(View(reservation));
        }
Esempio n. 2
0
        public async Task <IActionResult> ChoosePaymentMethod(int?id)
        {
            Models.Business.Reservation reservation = await _context.Reservations.Include(r => r.Customer).Include(r => r.Tickets).ThenInclude(t => t.Customer).Include(t => t.Tickets).ThenInclude(t => t.Flight).ThenInclude(f => f.FlightInfo).FirstAsync(r => r.ReservationID == id);

            ViewBag.RemainingMiles = reservation.Customer.Mileage - reservation.ReservationMileageCost;
            return(View(reservation));
        }
Esempio n. 3
0
        public async Task <ActionResult> ChangeTicketPrices(Int32 ReservationID)
        {
            Models.Business.Reservation reservation = await _context.Reservations.
                                                      Include(r => r.Tickets).ThenInclude(t => t.Customer).Include(t => t.Tickets).
                                                      ThenInclude(t => t.Flight).ThenInclude(f => f.FlightInfo).ThenInclude(f => f.Route).
                                                      ThenInclude(f => f.CityTo).FirstAsync(r => r.ReservationID == ReservationID);

            return(View(reservation));
        }
Esempio n. 4
0
        public async Task <ActionResult> ChangeDate(ReservationEditModel rem)
        {
            if (rem.NewDate < DateTime.Now)
            {
                String message = "You cannot change reservations to the past";
                return(RedirectToAction("Edit", "Reservation", new { id = rem.ReservationID, errorMessage = message }));
            }

            Models.Business.Reservation r = await _context.Reservations.Include(res => res.Tickets).FirstAsync(res => res.ReservationID == rem.ReservationID);

            Ticket             t     = _context.Tickets.Include(tic => tic.Flight).ThenInclude(f => f.FlightInfo).First(tic => tic.TicketID == r.Tickets.First().TicketID);
            FlightInfo         info  = _context.FlightInfos.Include(fi => fi.Route).First(fi => fi.FlightInfoID == t.Flight.FlightInfo.FlightInfoID);
            Route              route = _context.Routes.Include(ro => ro.CityFrom).Include(ro => ro.CityTo).First(ro => ro.RouteID == info.Route.RouteID);
            BookingSearchModel bsm   = new BookingSearchModel
            {
                DepartCityID   = route.CityFrom.CityID,
                DepartDate     = rem.NewDate,
                ArriveCityID   = route.CityTo.CityID,
                PassengerCount = rem.PassengerCount,
                ReservationID  = r.ReservationID,
                isRoundTrip    = rem.isRoundTrip
            };

            ViewBag.CityToName   = _context.Cities.FirstOrDefault(c => c.CityID == bsm.ArriveCityID).CityName;
            ViewBag.CityFromName = _context.Cities.FirstOrDefault(c => c.CityID == bsm.DepartCityID).CityName;
            var query = from f in _context.Flights
                        select f;

            query = query.Where(f => f.Date.Date == bsm.DepartDate.Date);
            query = query.Where(f => f.FlightInfo.Route.CityFrom.CityID == bsm.DepartCityID);
            query = query.Where(f => f.FlightInfo.Route.CityTo.CityID == bsm.ArriveCityID);
            query = query.Where(f => f.Canceled == false);
            foreach (Flight f in query)
            {
                //If there are not enough seats on flight delete flight from query
                if (!Utilities.GetTakenSeats.isAvailable(f.FlightID, bsm.PassengerCount, _context))
                {
                    query = query.Where(flight => flight.FlightID != f.FlightID);
                }
            }
            //Passing Booking Search Model information to view bag so it goes to ReservationController
            //There's probably a better way to do this
            ViewBag.DepartingFlightsQty = query.Count();
            ViewBag.isRoundTrip         = bsm.isRoundTrip;
            ViewBag.passengerCount      = bsm.PassengerCount;
            ViewBag.ReturnDate          = bsm.ArriveDate;
            ViewBag.ReservationID       = bsm.ReservationID;
            ViewBag.PrevFlightID        = rem.PrevFlightID;
            return(View("ReservationFlightResults", query.Include(f => f.FlightInfo)
                        .Include(f => f.FlightInfo.Route)
                        .Include(f => f.FlightInfo.Route.CityFrom)
                        .Include(f => f.FlightInfo.Route.CityTo)
                        .ToList()));
        }
Esempio n. 5
0
        //Last Action for Reservation Creation
        public async Task <IActionResult> Finalize(int?id)
        {
            Models.Business.Reservation dbReservation = _context.Reservations.Include(r => r.Customer).Include(r => r.Tickets).ThenInclude(r => r.Customer)
                                                        .Include(r => r.Tickets).ThenInclude(r => r.Flight).ThenInclude(r => r.FlightInfo).ThenInclude(r => r.Route).ThenInclude(r => r.CityFrom)
                                                        .Include(r => r.Tickets).ThenInclude(r => r.Flight).ThenInclude(r => r.FlightInfo).ThenInclude(r => r.Route).ThenInclude(r => r.CityTo)
                                                        .FirstOrDefault(r => r.ReservationID == id);
            dbReservation.ReservationComplete = true;
            _context.Update(dbReservation);
            await _context.SaveChangesAsync();

            String EmailBody;

            if (dbReservation.ReservationMethod == PaymentOptions.Cash)
            {
                EmailBody = "Thanks for your reservation. Your subtotal is: " + dbReservation.ReservationSubtotal + "The tax fee is: " + dbReservation.SalesTax + "Your total is: " + dbReservation.ReservationTotal;
            }
            else
            {
                Int32   remainingMiles;
                AppUser user = _context.Users.First(u => u.UserID == dbReservation.Customer.UserID);
                remainingMiles = Convert.ToInt32(user.Mileage) - dbReservation.ReservationMileageCost;
                user.Mileage   = remainingMiles;
                _context.Update(user);
                await _context.SaveChangesAsync();

                EmailBody = "Thanks for your reservation. Your subtotal is: " + dbReservation.ReservationMileageCost + "You have: " + remainingMiles + " miles left.";
            }
            try
            {
                Utilities.EmailMessaging.SendEmail(dbReservation.Customer.Email, "Reservation Confirmation", EmailBody);
            }
            catch
            {
                //Couldn't send email.
            }
            foreach (Ticket dbticket in dbReservation.Tickets)
            {
                String email      = dbticket.Customer.Email;
                String emailStuff = "Your Flight on Longhorn Airlines has been Booked!\nYour reservation number is " + dbReservation.ReservationID + "\nand your ticket number is " + dbticket.TicketID + "\nWe look forward to seeing you on " + dbticket.Flight.Date.ToString() + "\n at " + dbticket.Flight.FlightInfo.FlightTime.ToString() + " for your flight from " + dbticket.Flight.FlightInfo.Route.CityFrom.CityName + " to " + dbticket.Flight.FlightInfo.Route.CityTo.CityName + ".";

                try
                {
                    Utilities.EmailMessaging.SendEmail(email, "Reservation Confirmation", emailStuff);
                }
                catch
                {
                    //Couldn't send email.
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 6
0
 private void CreateTickets(Int32 ReservationID, Int32 flightID, Int32 passengerCount)
 {
     Models.Business.Reservation reservation = _context.Reservations.Include(r => r.Tickets).First(r => r.ReservationID == ReservationID);
     for (int i = 0; i < passengerCount; i++)
     {
         Ticket reservationTicket = new Ticket
         {
             Reservation = _context.Reservations.First(r => r.ReservationID == reservation.ReservationID),
             Flight      = _context.Flights.Include(f => f.FlightInfo).FirstOrDefault(f => f.FlightID == flightID)
         };
         reservation.Tickets.Add(reservationTicket);
         _context.Tickets.Add(reservationTicket);
         _context.Update(reservation);
     }
 }
Esempio n. 7
0
        // Handles creating one way reservations
        // Creates a blank one way reservation and adds {passengerCount} tickets to it if it's empty
        public async Task <ActionResult> CreateOneWayReservation(Int32 flightID, Int32 passengerCount, Int32?CustomerID)
        {
            Models.Business.Reservation reservation = await CreateBlankReservation(TypeOfReservation.OneWay, CustomerID);

            if (reservation.Tickets.Count() > 0)
            {
                return(RedirectToAction("Description", new { id = reservation.ReservationID }));
            }
            else
            {
                CreateTickets(reservation.ReservationID, flightID, passengerCount);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Description", new { id = reservation.ReservationID }));
            }
        }
Esempio n. 8
0
        //Last Action for modifying reservation
        public async Task <ActionResult> ModifyReservation(Int32 ReservationID, Int32 FlightID, Int32 PrevFlightID)
        {
            Models.Business.Reservation reservation = await _context.Reservations.Include(r => r.Tickets).ThenInclude(t => t.Customer).Include(r => r.Tickets).ThenInclude(t => t.Flight).FirstAsync(r => r.ReservationID == ReservationID);

            Flight flight = await _context.Flights.Include(f => f.Tickets).FirstAsync(f => f.FlightID == FlightID);

            Flight prevFlight = _context.Flights.Include(f => f.Tickets).First(f => f.FlightID == PrevFlightID);

            foreach (Ticket t in reservation.Tickets)
            {
                if (t.Flight.FlightID == PrevFlightID)
                {
                    t.Flight = flight;
                    t.Seat   = "";
                    prevFlight.Tickets.Remove(t);
                    flight.Tickets.Add(t);
                    _context.Update(t);
                    _context.Update(prevFlight);
                    _context.Update(flight);
                }
            }
            await _context.SaveChangesAsync();

            //if modification was done by customer, charge $50
            if (User.IsInRole("Customer"))
            {
                HashSet <AppUser> reservationCustomers = new HashSet <AppUser>();
                foreach (Ticket t in reservation.Tickets)
                {
                    reservationCustomers.Add(t.Customer);
                    if (t.Flight.FlightID == FlightID)
                    {
                        t.Fare += 50;
                        _context.Update(t);
                    }
                }
                foreach (AppUser customer in reservationCustomers)
                {
                    Utilities.EmailMessaging.SendEmail(customer.Email, "Team 6: Reservation Modification", "Your reservation has been modified. You've been charged $50.00 on your flight.");
                }
                await _context.SaveChangesAsync();

                ViewBag.ReservationID = ReservationID;
                return(View("Charge"));
            }
            return(RedirectToAction("Description", new { id = reservation.ReservationID }));
        }
Esempio n. 9
0
        // Creates blank reservation
        private async Task <Models.Business.Reservation> CreateBlankReservation(TypeOfReservation type, int?CustomerID)
        {
            Models.Business.Reservation reservation = new Models.Business.Reservation
            {
                ReservationNumber   = Utilities.GenerateReservationNumber.GetReservationNum(_context),
                ReservationType     = type,
                ReservationComplete = false,
                Tickets             = new List <Ticket>()
            };
            if (CustomerID.HasValue)
            {
                reservation.Customer = await _context.Users.FirstAsync(u => u.UserID == CustomerID.Value);
            }
            _context.Reservations.Add(reservation);
            await _context.SaveChangesAsync();

            return(reservation);
        }
Esempio n. 10
0
        public async Task <SelectList> GetReservationCustomersAsync(Int32 ReservationID, Int32?NewCustomerID)
        {
            Models.Business.Reservation reservation      = _context.Reservations.Include(r => r.Tickets).ThenInclude(t => t.Customer).First(r => r.ReservationID == ReservationID);
            HashSet <AppUser>           reservationUsers = new HashSet <AppUser>();

            foreach (Ticket t in reservation.Tickets)
            {
                if (t.Customer != null)
                {
                    reservationUsers.Add(t.Customer);
                }
            }
            reservationUsers.Add(await _userManager.FindByNameAsync(User.Identity.Name));
            if (NewCustomerID.HasValue)
            {
                reservationUsers.Add(_context.Users.First(u => u.UserID == NewCustomerID.Value));
            }
            return(new SelectList(reservationUsers, "UserID", "FirstName"));
        }
Esempio n. 11
0
        //TODO: Implement Round Trip
        public async Task <ActionResult> CreateRoundTripReservation(Int32 flightID, Int32 passengerCount, Int32 cityToID, Int32 cityFromID, DateTime returnDate, Int32?CustomerID)
        {
            Models.Business.Reservation reservation = await CreateBlankReservation(TypeOfReservation.RoundTrip, CustomerID);

            CreateTickets(reservation.ReservationID, flightID, passengerCount);
            await _context.SaveChangesAsync();

            BookingSearchModel bsm = new BookingSearchModel
            {
                DepartCityID   = cityToID,
                ArriveCityID   = cityFromID,
                DepartDate     = returnDate,
                ArriveDate     = returnDate,
                PassengerCount = passengerCount,
                isRoundTrip    = false,
                ReservationID  = reservation.ReservationID
            };

            return(ReturnFlightLookup(bsm));
        }
Esempio n. 12
0
        //Shows Reservation Confirmation Page
        public async Task <IActionResult> Confirm(int?id, String PaymentMethod)
        {
            Models.Business.Reservation reservation = await _context.Reservations.Include(r => r.Customer).Include(r => r.Tickets).ThenInclude(t => t.Customer).Include(t => t.Tickets).ThenInclude(t => t.Flight).ThenInclude(f => f.FlightInfo).FirstAsync(r => r.ReservationID == id);

            if (PaymentMethod == "Cash")
            {
                reservation.ReservationMethod = PaymentOptions.Cash;
            }
            else if (PaymentMethod == "Mileage")
            {
                reservation.ReservationMethod = PaymentOptions.Miles;
            }
            else
            {
                reservation.ReservationMethod = PaymentOptions.Cash;
            }
            _context.Update(reservation);
            await _context.SaveChangesAsync();

            ViewBag.RemainingMiles = reservation.Customer.Mileage - reservation.ReservationMileageCost;
            return(View(reservation));
        }
Esempio n. 13
0
        public async Task <IActionResult> ChangeSeats(Int32 id)
        {
            Models.Business.Reservation reservation = _context.Reservations.Include(r => r.Tickets).ThenInclude(t => t.Customer).Include(t => t.Tickets).ThenInclude(t => t.Flight).ThenInclude(f => f.FlightInfo).ThenInclude(f => f.Route).ThenInclude(f => f.CityTo).First(r => r.ReservationID == id);

            return(View(reservation));
        }
Esempio n. 14
0
        // GET: Reservation/Details/5
        // Details page shows all tickets and allows for ticket change
        // This is the default page everyone sees after a reservation is created
        public async Task <IActionResult> Description(int id)
        {
            Models.Business.Reservation reservation = await _context.Reservations.Include(r => r.Tickets).ThenInclude(t => t.Customer).Include(t => t.Tickets).ThenInclude(t => t.Flight).ThenInclude(f => f.FlightInfo).ThenInclude(f => f.Route).ThenInclude(f => f.CityTo).FirstAsync(r => r.ReservationID == id);

            return(View(reservation));
        }