Exemple #1
0
        public async Task <IActionResult> MyBookingsAsync(string UserId)
        {
            // get all available bookings
            var bookings = await _bookRepository.GetAllAsync();

            List <UserReservedFlightVM> _userReservedFlightsVM = new List <UserReservedFlightVM>();

            // transform from Booking to BookingVM and take into consideration only user specific bookings
            foreach (var booking in bookings)
            {
                //if we found a booking
                if (booking.AppUserID == UserId)
                {
                    //get the flight
                    var result = _flightRepository.GetOneByConditionAsync(u => u.Id == booking.FlightId);

                    var flight = result.Result;
                    var _userReservedFlight = new UserReservedFlightVM
                    {
                        PlaneName     = flight.PlaneName,
                        Price         = flight.Price,
                        Route         = flight.Route,
                        Departure     = flight.Departure,
                        Arrive        = flight.Arrive,
                        IsCancelled   = booking.IsCancelled,
                        SeatsReserved = booking.SeatsReserved,
                        BookId        = booking.Id,
                        PhotoPath     = flight.PhotoPath
                    };

                    _userReservedFlightsVM.Add(_userReservedFlight);
                }
            }
            return(View(_userReservedFlightsVM));
        }
Exemple #2
0
        public async Task <IActionResult> MakeBooking(string flightId, string userId)
        {
            var result = _flightRepository.GetOneByConditionAsync(u => u.Id == int.Parse(flightId));
            var flight = result.Result;

            UserReservedFlightVM userReservedFlight = new UserReservedFlightVM
            {
                PlaneName = flight.PlaneName,
                Price     = flight.Price,
                Route     = flight.Route,
                Departure = flight.Departure,
                Arrive    = flight.Arrive,
                UserId    = userId,
                FlightId  = flightId,
                PhotoPath = flight.PhotoPath
            };

            return(View(userReservedFlight));
        }