Ejemplo n.º 1
0
        public void Post([FromBody] FlightPlan fp)
        {
            string id = this.RandomString();

            fp.flightPlanID = id;
            Flight flight = new Flight();

            flight.flight_id    = id;
            flight.passengers   = fp.passengers;
            flight.company_name = fp.company_name;
            flight.date_time    = fp.initial_location.date_time;
            flight.longtitude   = fp.initial_location.longitude;
            flight.latitude     = fp.initial_location.latitude;
            flight.is_external  = false;
            double end = 0;

            for (int i = 0; i < fp.segments.Count; i++)
            {
                end += fp.segments[i].timespan_seconds;
            }

            DateTime landing = new DateTime();

            landing             = fp.initial_location.date_time.AddSeconds(end);
            flight.landing_time = landing;
            FlightManager.FlightsDic.TryAdd(flight.flight_id, flight);
            managerFlightPlan.AddFlightPlan(fp);
        }
        /*
         * This method gets an object (JSON) and parse it.
         * for each flight we create a new flight, flight plan, initial location and segments objects
         * and fill each related part.
         * when we done parsing and creating each object we add it to our DBs.
         */
        private async Task <IActionResult> AddObjects(dynamic bodyObj)
        {
            int      passengers  = bodyObj["passengers"];
            string   companyName = bodyObj["company_name"];
            double   longitude   = bodyObj["initial_location"]["longitude"];
            double   latitude    = bodyObj["initial_location"]["latitude"];
            DateTime dateTime    = bodyObj["initial_location"]["date_time"];
            var      segmentsObj = bodyObj["segments"];

            var newFlight = _flightManager.AddFlight();
            await _flightContext.FlightItems.AddAsync(newFlight);

            var newFlightPlan = _flightPlanManager.AddFlightPlan
                                    (newFlight, passengers, companyName);
            await _flightContext.FlightPlanItems.AddAsync(newFlightPlan);

            var newInitialLocation = AddInitialLocation
                                         (newFlightPlan, longitude, latitude, dateTime);

            DateTime end = AddSegments(dateTime, segmentsObj, newFlightPlan);

            newFlightPlan.EndTime = end;

            return(await UpdateDb(newFlight, newFlightPlan, newInitialLocation));
        }
Ejemplo n.º 3
0
        public ActionResult Post([FromBody] FlightPlan flightPlan)
        {
            if (!CheckObjects.CheckFlightPlan(flightPlan))
            {
                return(BadRequest());
            }
            string idOfAddedFlightPlan = flightPlanManager.AddFlightPlan(flightPlan);

            return(CreatedAtAction(actionName: "GetFlightPlan",
                                   new { id = idOfAddedFlightPlan }, flightPlan));
        }
Ejemplo n.º 4
0
 public IActionResult Post([FromBody] FlightPlan value)
 {
     try
     {
         flightPlanManager.AddFlightPlan(value);
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
     return(Ok());
 }
        public ActionResult <string> Post([FromBody] FlightPlan flightPlan)
        {
            string isValid = CheckValidationOfFlightPlan(flightPlan);

            if (isValid.CompareTo(Valid) != 0)
            {
                return(BadRequest(isValid));
            }
            string id = manager.AddFlightPlan(flightPlan);

            return(Ok(id));
        }
Ejemplo n.º 6
0
        public StatusCodeResult Post(FlightPlan fp)
        {
            try
            {
                // Get the randomized ID for the posted flight plan.
                string id = this.RandomString();
                fp.flightPlanID = id;
                // Create a new flight object with the compatible properties as the posted flight plan.
                Flight flight = new Flight();
                flight.flight_id        = id;
                flight.passengers       = fp.passengers;
                flight.company_name     = fp.company_name;
                flight.starting_datails = fp.initial_location.date_time.ToString("dd-MM-yyyy");
                flight.initial_location = "Lat: " + fp.initial_location.latitude.ToString() + "  Lon: " + fp
                                          .initial_location.longitude.ToString();
                flight.date_time   = fp.initial_location.date_time;
                flight.longitude   = fp.initial_location.longitude;
                flight.latitude    = fp.initial_location.latitude;
                flight.is_external = false;
                double end = 0;

                int i;
                for (i = 0; i < fp.segments.Count; i++)
                {
                    // Count the total time in seconds of the whole segments.
                    end += fp.segments[i].timespan_seconds;
                }

                flight.final_location = "Lat: " + fp.segments[i - 1].latitude.ToString() + "  Lon: " +
                                        fp.segments[i - 1].longitude.ToString();
                DateTime landing = new DateTime();
                landing                = fp.initial_location.date_time.AddSeconds(end);
                flight.landing_time    = landing;
                flight.landing_details = landing.ToString("dd-MM-yyyy");
                FlightManager.FlightsDic.TryAdd(flight.flight_id, flight);
                managerFlightPlan.AddFlightPlan(fp);
                return(StatusCode(StatusCodes.Status200OK));
            } catch
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
        }
Ejemplo n.º 7
0
        //public void Post([FromBody] FlightPlan fp)
        public void Post(FlightPlan fp)
        {
            string id = this.RandomString();

            fp.flightPlanID = id;
            Flight flight = new Flight();

            flight.flight_id        = id;
            flight.passengers       = fp.passengers;
            flight.company_name     = fp.company_name;
            flight.starting_time    = fp.initial_location.date_time;
            flight.starting_datails = fp.initial_location.date_time.ToString("dd-MM-yyyy");
            flight.initial_location = "Lat: " + fp.initial_location.latitude.ToString() + "  Lon: " + fp
                                      .initial_location.longitude.ToString();
            flight.date_time   = fp.initial_location.date_time;
            flight.longitude   = fp.initial_location.longitude;
            flight.latitude    = fp.initial_location.latitude;
            flight.is_external = false;
            double end = 0;

            int i;

            for (i = 0; i < fp.segments.Count; i++)
            {
                end += fp.segments[i].timespan_seconds;
            }

            flight.final_location = "Lat: " + fp.segments[i - 1].latitude.ToString() + "  Lon: " +
                                    fp.segments[i - 1].longitude.ToString();
            DateTime landing = new DateTime();

            landing                = fp.initial_location.date_time.AddSeconds(end);
            flight.landing_time    = landing;
            flight.landing_details = landing.ToString("dd-MM-yyyy");
            FlightManager.FlightsDic.TryAdd(flight.flight_id, flight);
            managerFlightPlan.AddFlightPlan(fp);
        }
Ejemplo n.º 8
0
 public ActionResult <FlightPlan> AddFlightPlan(FlightPlan flightPlan)
 {
     return(Ok(flightPlanManager.AddFlightPlan(flightPlan)));
 }
Ejemplo n.º 9
0
        public ActionResult Post([FromBody] FlightPlan flightPlan)
        {
            string idOfAddedFlightPlan = flightPlanManager.AddFlightPlan(flightPlan);

            return(CreatedAtAction(actionName: "GetFlightPlan", new { id = idOfAddedFlightPlan }, flightPlan));
        }