private bool validateFlightPlan(FlightPlan flightPlan)
        {
            foreach (PropertyInfo propertyInfo in flightPlan.GetType().GetProperties())
            {
                if (propertyInfo.Name == nameof(FlightPlan.Id))
                {
                    continue;
                }
                object?value = propertyInfo.GetValue(flightPlan);
                if (value == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] FlightPlan plan)
        {
            try
            {
                //check if all fields got are not null
                bool isOk = plan.GetType().GetProperties().All(p => p.GetValue(plan) != null);
                if (isOk)
                {
                    await flightsModel.AddFlightPlan(plan);

                    return(Ok());
                }

                return(BadRequest("Property can't be null"));
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }