Beispiel #1
0
        public ActionResult Book(BookFlightViewModel bookFlightViewModel, int id)
        {
            string usrUsername  = Session["Username"].ToString();
            User   user         = db.Users.Where(u => u.Username == usrUsername).FirstOrDefault();
            Flight flight       = db.Flights.Find(id);
            bool   error        = false;
            int    numOfTickets = bookFlightViewModel.NumOfTickets;

            if (ModelState.IsValid)
            {
                int ticketsLeft = flight.TicketsLeft;
                if (numOfTickets > ticketsLeft)
                {
                    ViewBag.TicketsErrorMessage = "Not enough tickets for flight!";
                    error = true;
                }

                // if user has already booked that flight
                if (db.Reservations.Any(r => r.UserId == user.Id && r.FlightId == flight.Id))
                {
                    ViewBag.ErrorMessage = "User je vec izvrsio rezervaciju za ovaj let!";
                    error = true;
                }
                if (user.Count < flight.price * numOfTickets)
                {
                    ViewBag.CountErrorMessage = "You don't have enough money on your count!";
                    error = true;
                }

                Reservation reservation = new Reservation
                {
                    Flight          = flight,
                    User            = user,
                    NumberOfTickets = numOfTickets
                };

                if (!error)
                {
                    // update Flight tickets left
                    flight.TicketsLeft -= numOfTickets;
                    // update user's count
                    user.Count      -= flight.price * numOfTickets;
                    Session["Count"] = user.Count;
                    db.Reservations.Add(reservation);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            //bookFlightViewModel.Flight = flight;
            return(View(bookFlightViewModel));
        }
Beispiel #2
0
        public ActionResult BookFlight(int flightId)
        {
            BookFlightViewModel flightBookingViewModel = new BookFlightViewModel();

            var flight = db.Flights.FirstOrDefault(f => f.Id == flightId);

            flightBookingViewModel.Flight   = flight;
            flightBookingViewModel.FlightId = flightId;

            string bookedSeats = string.Join(",", (db.Bookings.Where(b => b.FlightId == flightId).Select(b => b.Seat)).ToArray());

            TempData["BookedSeats"] = bookedSeats;

            return(View(flightBookingViewModel));
        }
Beispiel #3
0
        public ActionResult BookFlight(BookFlightViewModel bookingFlightViewModel)
        {
            string sessionUserId = (User.Identity.Name.Split('|')[1]);

            Booking booking = new Booking()
            {
                UserId   = Convert.ToInt32(sessionUserId),
                FlightId = bookingFlightViewModel.FlightId,
                Seat     = bookingFlightViewModel.SeatsSelected
            };

            db.Bookings.Add(booking);
            db.SaveChanges();

            return(RedirectToAction("BookedFlight", "Flight"));
        }
Beispiel #4
0
        public async Task <IActionResult> Book(int flightId, string travelClassCode, int adults, int children, int infants)
        {
            if (!await _flightInfoService.FlightExistsAsync(flightId))
            {
                return(NotFound());
            }

            FlightInformation flightInformation = await _flightInfoService.GetFlightByIdAsync(flightId, adults, children, infants);

            TravelClassDto travelClass = await _flightInfoService.GetTravelClassByCodeAsync(travelClassCode);

            List <NationalityDto> nationalities = await _passengerInfoService.GetNationalitiesAsync();

            BookFlightViewModel viewModel = new BookFlightViewModel
            {
                FlightInformation = flightInformation,
                Passengers        = new List <PassengerDto>(),
                TravelClass       = travelClass,
                Nationalities     = nationalities
            };

            for (int i = 0; i < adults; i++)
            {
                viewModel.Passengers.Add(new PassengerDto {
                    AgeBracket = AgeBracket.Adult, DateOfBirth = DateTime.Today
                });
            }

            for (int i = 0; i < children; i++)
            {
                viewModel.Passengers.Add(new PassengerDto {
                    AgeBracket = AgeBracket.Child, DateOfBirth = DateTime.Today
                });
            }

            for (int i = 0; i < infants; i++)
            {
                viewModel.Passengers.Add(new PassengerDto {
                    AgeBracket = AgeBracket.Infant, DateOfBirth = DateTime.Today
                });
            }

            return(View(viewModel));
        }
        //[HttpPost]
        //public ActionResult Book(BookFlightViewModel bookDetail)
        //{
        //    //BookFlightViewModel bfVm = JsonConvert.DeserializeObject<BookFlightViewModel>(bookingDetail);
        //    //return View(bookingDetail);
        //    return RedirectToAction("Booking", "SearchFlight", new { bookingDetail = bookDetail });
        //}

        public ActionResult Booking(string bookingDetail)
        {
            BookFlightViewModel bfVm = JsonConvert.DeserializeObject <BookFlightViewModel>(bookingDetail);
            var authenticatedUser    = Common.Common.GetAuthenticatedUser();

            if (authenticatedUser > 0)
            {
                var userinfo = db.tblUserInformations.Where(c => c.ID == authenticatedUser).FirstOrDefault();
                bfVm.ID         = userinfo.ID;
                bfVm.FirstName  = userinfo.FirstName;
                bfVm.LastName   = userinfo.LastName;
                bfVm.Email      = userinfo.Email;
                bfVm.PhoneNo    = userinfo.PhoneNo;
                bfVm.Address    = userinfo.Address;
                bfVm.City       = userinfo.City;
                bfVm.Country    = userinfo.Country;
                bfVm.PostalCode = userinfo.PostalCode;
            }
            return(View(bfVm));
        }
Beispiel #6
0
        public ActionResult Book(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Flight flight = db.Flights.Find(id);

            if (flight == null)
            {
                return(HttpNotFound());
            }
            BookFlightViewModel viewModel = new BookFlightViewModel
            {
                Flight       = flight,
                NumOfTickets = 0
            };

            return(View(viewModel));
        }
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     ViewModel = DIHelper.Resolve <BookFlightViewModel>();
     ViewModel.Initialize();
 }
        public ActionResult Booking(BookFlightViewModel bfVm)
        {
            var user = new tblUserInformation();

            if (bfVm.ID > 0)
            {
                user = db.tblUserInformations.Where(c => c.ID == bfVm.ID).FirstOrDefault();
            }
            else
            {
                user.FirstName  = bfVm.FirstName;
                user.LastName   = bfVm.LastName;
                user.Email      = bfVm.Email;
                user.Password   = "******";
                user.UserTypeID = 4;
                user.PhoneNo    = bfVm.PhoneNo;
                user.Address    = bfVm.Address;
                user.City       = bfVm.City;
                user.Country    = bfVm.Country;
                user.PostalCode = bfVm.PostalCode;
                db.tblUserInformations.Add(user);
                db.SaveChanges();
            }

            var flightBook = new tblFlightBook();

            flightBook.UserID     = user.ID;
            flightBook.TripTypeID = Convert.ToInt32(bfVm.FlightType);
            db.tblFlightBooks.Add(flightBook);
            db.SaveChanges();

            List <PassengerDetailViewModel> passengerDetailList = JsonConvert.DeserializeObject <List <PassengerDetailViewModel> >(bfVm.jsonPassengerDetail);

            //departure
            foreach (var pdetail in passengerDetailList)
            {
                var flightBookDetail = new tblFlightBookDetail();
                flightBookDetail.BookID           = flightBook.ID;
                flightBookDetail.FlightScheduleID = Convert.ToInt32(bfVm.DepartureFlight);
                flightBookDetail.ClassID          = Convert.ToInt32(bfVm.DepartureFlightClass);
                flightBookDetail.BookingDate      = DateTime.Now;
                db.tblFlightBookDetails.Add(flightBookDetail);
                db.SaveChanges();

                var passengerDetail = new tblPassengerDetail();
                passengerDetail.BookFlightID  = flightBookDetail.ID;
                passengerDetail.PassengerType = pdetail.PassengerType;
                passengerDetail.FirstName     = pdetail.FirstName;
                passengerDetail.LastName      = pdetail.LastName;
                passengerDetail.Gender        = pdetail.Gender;
                passengerDetail.Phone         = pdetail.Phone;
                passengerDetail.Address       = pdetail.Address;
                db.tblPassengerDetails.Add(passengerDetail);
                db.SaveChanges();

                if (bfVm.FlightType == "2")
                {
                    var returnflightBookDetail = new tblFlightBookDetail();
                    returnflightBookDetail.BookID           = flightBook.ID;
                    returnflightBookDetail.FlightScheduleID = Convert.ToInt32(bfVm.ReturnFlight);
                    returnflightBookDetail.ClassID          = Convert.ToInt32(bfVm.ReturnFlightClass);
                    returnflightBookDetail.BookingDate      = DateTime.Now;
                    db.tblFlightBookDetails.Add(returnflightBookDetail);
                    db.SaveChanges();

                    var returnpassengerDetail = new tblPassengerDetail();
                    returnpassengerDetail.BookFlightID  = returnflightBookDetail.ID;
                    returnpassengerDetail.PassengerType = pdetail.PassengerType;
                    returnpassengerDetail.FirstName     = pdetail.FirstName;
                    returnpassengerDetail.LastName      = pdetail.LastName;
                    returnpassengerDetail.Gender        = pdetail.Gender;
                    returnpassengerDetail.Phone         = pdetail.Phone;
                    returnpassengerDetail.Address       = pdetail.Address;
                    db.tblPassengerDetails.Add(returnpassengerDetail);
                    db.SaveChanges();
                }
            }



            return(RedirectToAction("FlightTicket", "SearchFlight", new { bookId = flightBook.ID }));
        }