public async Task <ActionResult <FlightCompany> > GetFlightCompany(int id) { var flightCompany = await _context.FlightCompanies.Include(f => f.Flights).ThenInclude(l => l.LocationTransfers).ThenInclude(r => r.Location).FirstOrDefaultAsync(i => i.ID == id); foreach (var flight in flightCompany.Flights) { List <Seat> seats = new List <Seat>(); foreach (var seat in _context.Seats) { if (flight.ID == seat.FlightID) { seats.Add(seat); } } flight.Seats = seats; } if (flightCompany == null) { return(NotFound()); } foreach (var item in flightCompany.Flights) { flightFunction.locationTransfersOrder(item); } flightCompany.Flights = flightFunction.checkFlightDate(flightCompany.Flights); flightCompany.Rating = flightCompanyFunction.calculateFlightRating(flightCompany.ID); return(flightCompany); }
public async Task <ActionResult <Flight> > GetFlight(int id) { var flight = _context.Flights.Include(l => l.LocationTransfers).ThenInclude(r => r.Location).FirstOrDefault(i => i.ID == id); List <Seat> seats = new List <Seat>(); foreach (var item in _context.Seats.ToList()) { if (item.FlightID == flight.ID) { seats.Add(item); } } flight.Seats = seats; if (flight == null) { return(NotFound()); } flightFunctions.locationTransfersOrder(flight); return(flight); }