public async Task <IActionResult> Create([FromBody] FlightViewModel flight) { try { var theGate = await FlightService.GetFlightsByGateIdAsync(flight.GateId); var theFlight = TheModelFactory.Create(flight); var flightId = FlightService.AddFlightToGate(theFlight, theGate); if (flightId == 0) { return(StatusCode(500, "Couldn't create flight.")); } var created = FlightService.GetFlightById(flightId); return(CreatedAtRoute("", created)); } catch (Exception ex) { return(BadRequest(ex)); } }