public async Task <ActionResult <FlightPlan> > GetFlightPlan(string id) { //find the flighplan in db FlightPlanDB flightPlanDB = sql.FlightsPlanById(id); FlightPlan flightPlan; if (flightPlanDB == null) { try { flightPlan = await externalFlights.GetExternalFlightById(id); } catch { return(NotFound()); } } else { flightPlan = flightPlanDB.GetFlightPlan(); } if (flightPlan == null) { return(NotFound()); } return(Ok(flightPlan)); }
public FlightPlanDB FlightsPlanById(string id) { InitialLocation initialLocation; FlightPlanDB flightPlanDB = null; FlightPlan flightPlan; string query = $"SELECT * FROM Flight WHERE id = '{id}'"; SQLiteCommand myCommand = new SQLiteCommand(query, databaseObject.myConnection); ////databaseObject.OpenConnection(); SQLiteDataReader result = myCommand.ExecuteReader(); // Creating a List of integers if (result.HasRows) { while (result.Read()) { string company = $"{result["company"]}"; int passenger = Convert.ToInt32($"{result["passengers"]}"); //create initial location initialLocation = new InitialLocation(Convert.ToDouble( $"{result["start_longitude"]}"), Convert.ToDouble($"{result["start_latitude"]}"), FromStringToDate($"{result["start_time"]}")); //create flightplan flightPlan = new FlightPlan(passenger, company, initialLocation, SegmentList(id)); flightPlanDB = new FlightPlanDB(id, flightPlan); } } //databaseObject.CloseConnection(); return(flightPlanDB); }