public async Task <ActionResult <FlightPlan> > PostFlightPlan(FlightPlan flightPlan) { _context.FlightPlan.Add(flightPlan); //Generate a unique key for new flight. do { flightPlan.FlightID = FlightPlan.GenerateFlightKey(); //As long as generated key is identical to a key in DB, generate a new one. } while (_context.FlightPlan.Count(x => x.FlightID == flightPlan.FlightID) > 0); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFlightPlan", new { id = flightPlan.FlightID }, flightPlan)); }