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))); }
public async Task <IActionResult> MemberAccountDetails() { PublicMemberAccDetVM vm = new PublicMemberAccDetVM() { User = await _globalRepo.GetCurrentUserAsync() }; var bookings = (await _bookingRepo.GetMemberBookings(vm.User.Id.ToString())); var bookingsFlightList = bookings.Select(b => b.GoFlightId).Concat(bookings.Select(b => b.ReturnFlightId)); vm.LatestFlight = (await _flightRepo.GetAllByFlightId(bookingsFlightList)).Where(t => t.DepartDateTime >= DateTime.Now).OrderBy(f => f.DepartDateTime).FirstOrDefault(); if (vm.LatestFlight != null) { vm.LatestFlight.OriginLoc1 = await _countryRepo.GetLocById(vm.LatestFlight.OriginLocID); vm.LatestFlight.DestLoc1 = await _countryRepo.GetLocById(vm.LatestFlight.DestLocID); } return(View(vm)); }