コード例 #1
0
        public ActionResult <string> AddFlightPlan([FromBody] FlightPlan plan)
        {
            try
            {
                // Returns id that DB gave the plan or null if it's already inside.
                string id = manager.InsertFlightPlan(plan);

                if (id != null)
                {
                    return(Ok(id));
                }
                else
                {
                    // Had id in the dictionary already
                    // (after trying to give a unique id for 30 times)
                    return(BadRequest("Had id in the dictionary already. Try again!"));
                }
            }
            // If date and time not in format exception has thrown and we return bad request.
            catch (FormatException)
            {
                return(BadRequest("Date and time not in format"));
            }
            // If any other exception is thrown we return bad request with a message.
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }