Exemplo n.º 1
0
        public async Task <IActionResult> GetMemberBookings()
        {
            //get bookings of current user
            var bookings = (await _bookingRepo.GetMemberBookings(_globalRepo.GetCurrentUserId().ToString())).ToList();

            //merge all flightIds and get all related flights and location details.
            var flightIds = bookings.Select(s => s.GoFlightId).Concat(bookings.Select(s => s.ReturnFlightId)).Distinct();
            var flights   = await _flightRepo.GetAllByFlightId(flightIds);

            var locIds = flights.Select(b => b.OriginLocID).Concat(flights.Select(b => b.DestLocID)).Distinct();
            var loc    = await _countryRepo.GetAllLocById(locIds);

            //fill in details of all bookings for current user
            for (int idx = 0; idx < bookings.Count(); idx++)
            {
                bookings[idx].GoFlight           = flights.Single(s => s.ID == bookings[idx].GoFlightId);
                bookings[idx].GoFlight.OriginLoc = loc.Single(c => c.ID == bookings[idx].GoFlight.OriginLocID);
                bookings[idx].GoFlight.DestLoc   = loc.Single(c => c.ID == bookings[idx].GoFlight.DestLocID);
                if (bookings[idx].ReturnFlightId > 0)
                {
                    bookings[idx].ReturnFlight           = flights.Single(s => s.ID == bookings[idx].ReturnFlightId);
                    bookings[idx].ReturnFlight.OriginLoc = loc.Single(c => c.ID == bookings[idx].ReturnFlight.OriginLocID);
                    bookings[idx].ReturnFlight.DestLoc   = loc.Single(c => c.ID == bookings[idx].ReturnFlight.DestLocID);
                }
            }
            return(View(bookings.OrderByDescending(b => b.ID)));
        }