Exemplo n.º 1
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()));
        }
 public IActionResult Index(BookingSearchModel model, String errorMessage)
 {
     if (errorMessage != null && errorMessage != "")
     {
         ViewBag.ErrorMessage = errorMessage;
     }
     if (User.IsInRole("Employee"))
     {
         return(View("../EmployeeViews/EmployeeIndex"));
     }
     ViewBag.AllCities = GetAllCities();
     return(View(model));
 }
        public IActionResult FlightResults(BookingSearchModel bookingSearchModel)
        {
            String cityToName   = _db.Cities.FirstOrDefault(c => c.CityID == bookingSearchModel.ArriveCityID).CityName;;
            String cityFromName = _db.Cities.FirstOrDefault(c => c.CityID == bookingSearchModel.DepartCityID).CityName;;

            ViewBag.CityToName   = cityToName;
            ViewBag.CityFromName = cityFromName;
            if (cityToName == cityFromName)
            {
                String message = "Cities cannot be the same";
                return(RedirectToAction("Index", "Home", new { errorMessage = message }));
            }
            if (bookingSearchModel.DepartDate.Date < DateTime.Now.Date || bookingSearchModel.ArriveDate.Date < DateTime.Now.Date)
            {
                String message = "You cannot get flights in the past";
                return(RedirectToAction("Index", "Home", new { errorMessage = message }));
            }
            var query = from f in _db.Flights
                        select f;

            query = query.Where(f => f.Date.Date == bookingSearchModel.DepartDate.Date);
            query = query.Where(f => f.FlightInfo.Route.CityFrom.CityID == bookingSearchModel.DepartCityID);
            query = query.Where(f => f.FlightInfo.Route.CityTo.CityID == bookingSearchModel.ArriveCityID);
            query = query.Where(f => f.hasDeparted == false);
            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, bookingSearchModel.PassengerCount, _db))
                {
                    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         = bookingSearchModel.isRoundTrip;
            ViewBag.passengerCount      = bookingSearchModel.PassengerCount;
            ViewBag.ReturnDate          = bookingSearchModel.ArriveDate;
            return(View("FlightResults", query.Include(f => f.FlightInfo)
                        .Include(f => f.FlightInfo.Route)
                        .Include(f => f.FlightInfo.Route.CityFrom)
                        .Include(f => f.FlightInfo.Route.CityTo)
                        .ToList()));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        public ActionResult ReturnFlightLookup(BookingSearchModel bookingSearchModel)
        {
            ViewBag.CityToName   = _context.Cities.FirstOrDefault(c => c.CityID == bookingSearchModel.ArriveCityID).CityName;
            ViewBag.CityFromName = _context.Cities.FirstOrDefault(c => c.CityID == bookingSearchModel.DepartCityID).CityName;
            var query = from f in _context.Flights
                        select f;

            query = query.Where(f => f.Date.Date == bookingSearchModel.DepartDate.Date);
            query = query.Where(f => f.FlightInfo.Route.CityFrom.CityID == bookingSearchModel.DepartCityID);
            query = query.Where(f => f.FlightInfo.Route.CityTo.CityID == bookingSearchModel.ArriveCityID);

            //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         = bookingSearchModel.isRoundTrip;
            ViewBag.passengerCount      = bookingSearchModel.PassengerCount;
            ViewBag.reservationID       = bookingSearchModel.ReservationID;
            return(View("ReturnLookup", query.Include(f => f.FlightInfo)
                        .Include(f => f.FlightInfo.Route)
                        .Include(f => f.FlightInfo.Route.CityFrom)
                        .Include(f => f.FlightInfo.Route.CityTo)
                        .ToList()));
        }
Exemplo n.º 6
0
        public async Task <List <BookingModel> > BookingSearchAsync(BookingSearchModel bookingSearchModel)
        {
            DateTime?dateComponent = null;

            if (bookingSearchModel.Date.HasValue)
            {
                dateComponent = bookingSearchModel.Date.Value.Date;
            }

            var bookings = await _context.Bookings.AsNoTracking <Booking>().Where(b =>
                                                                                  (bookingSearchModel.BookingReference == null || bookingSearchModel.BookingReference == b.BookingReference) &&
                                                                                  (bookingSearchModel.ReadersTicket == null || bookingSearchModel.ReadersTicket == b.ReaderTicket) &&
                                                                                  (dateComponent == null || dateComponent == b.VisitStartDate.Date) &&
                                                                                  (String.IsNullOrEmpty(bookingSearchModel.LastName) || b.LastName.Contains(bookingSearchModel.LastName))
                                                                                  ).Include(b => b.BookingType).Include(b => b.BookingStatus)
                           .Include(b => b.Seat).ThenInclude(s => s.SeatType)
                           .Include(b => b.OrderDocuments)
                           .TagWith <Booking>("Search of Bookings").ToListAsync();

            var bookingModels = bookings.Select(b => new BookingModel()
            {
                Id = b.Id,
                BookingReference       = b.BookingReference,
                BookingType            = (BookingTypes)b.BookingType.Id,
                BookingStatus          = (BookingStatuses)b.BookingStatusId,
                FirstName              = b.FirstName,
                LastName               = b.LastName,
                Email                  = b.Email,
                Phone                  = b.Phone,
                CreatedDate            = b.CreatedDate,
                CompleteByDate         = b.CompleteByDate,
                AdditionalRequirements = b.AdditionalRequirements,
                Comments               = b.Comments,
                IsAcceptCovidCharter   = b.IsAcceptCovidCharter,
                IsAcceptTsAndCs        = b.IsAcceptTsAndCs,
                IsNoFaceCovering       = b.IsNoFaceCovering,
                IsNoShow               = b.IsNoShow,
                ReaderTicket           = b.ReaderTicket,
                SeatId                 = b.SeatId,
                SeatNumber             = b.Seat.Number,
                SeatType               = (SeatTypes)b.Seat.SeatTypeId,
                SeatTypeDescription    = b.Seat.SeatType.Description,
                VisitStartDate         = b.VisitStartDate,
                VisitEndDate           = b.VisitEndDate,
                LastModifiedBy         = b.LastModifiedBy,
                OrderDocuments         = AddOrderDocuments(b)
            });

            return(bookingModels.ToList());

            List <OrderDocumentModel> AddOrderDocuments(Booking b)
            {
                var orderDocumentList = new List <OrderDocumentModel>();

                foreach (Booking booking in bookings)
                {
                    foreach (OrderDocument od in booking.OrderDocuments)
                    {
                        orderDocumentList.Add(new OrderDocumentModel()
                        {
                            Id = od.Id,
                            DocumentReference = od.DocumentReference,
                            Description       = od.Description,
                            PieceId           = od.PieceId,
                            PieceReference    = od.PieceReference,
                            ItemReference     = od.ItemReference,
                            ClassNumber       = od.ClassNumber,
                            SubClassNumber    = od.SubClassNumber,
                            LetterCode        = od.LetterCode,
                            IsReserve         = od.IsReserve,
                            Site = od.Site
                        });
                    }
                }

                return(orderDocumentList);
            }
        }
 public IActionResult bookForCust(BookingSearchModel model)
 {
     ViewBag.AllCities = GetAllCities();
     return(View("Index", model));
 }
Exemplo n.º 8
0
        public async Task <ActionResult <Booking> > SearchBookings([FromQuery] BookingSearchModel bookingSearchModel)
        {
            var result = await _bookingService.BookingSearchAsync(bookingSearchModel);

            return(Ok(result));
        }