public ActionResult AddFlightPlan([FromBody] JsonElement flightPlanJson) { FlightPlan flightPlan; var myUtils = new Utils(); string flightPlanString = flightPlanJson.ToString(); string error = "Received invalid flight plan"; // check if the flight plan json object is valid var flightPlanJObject = JObject.Parse(flightPlanString); if (!myUtils.IsFlightPlanJObjectValid(flightPlanJObject)) { return(BadRequest(error)); } try { // trying to deserialize the json object into a flight plan object flightPlan = JsonConvert.DeserializeObject <FlightPlan>(flightPlanString); } catch { return(BadRequest(error)); } // trying to add the flight plan if (myFlightsManager.AddFlightPlan(flightPlan)) { return(Ok()); } else { return(BadRequest(error)); } }
public IActionResult AddFlightPlan([FromBody] FlightPlan flightPlan) { if (_flightsManager.AddFlightPlan(flightPlan)) { return(Ok()); } return(BadRequest(new Error("Flight plan could not be added."))); }