/*
         * 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));
        }
示例#2
0
        public void Post(FlightVM flight)
        {
            var _flight = new Flight {
                Id = flight.Id, PlaneName = flight.PlaneName, Seats = flight.Seats, Route = flight.Route
            };

            _manager.AddFlight(_flight);
        }
示例#3
0
 public ActionResult Create(FlightViewModel flight)
 {
     if (ModelState.IsValid)
     {
         //unitOfWork.FlightRepository.AddFlight(
         flightManager.AddFlight(
             flight.AirlineName,
             flight.Origin,
             flight.Destination,
             flight.Year,
             flight.Month,
             flight.Day,
             flight.FlightId);
         //unitOfWork.Save();
         TempData["Message"] = this.flightManager.Message;
         return(RedirectToAction("Create", "Flight"));
     }
     return(View(flight));
 }
 public void Post([FromBody] Flight f)
 {
     managerFlight.AddFlight(f);
 }
示例#5
0
 public void Post(Flights f)
 {
     FlightManager.AddFlight(f);
 }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Length == 0)
            {
                lblError.Text = "Flight Name Can't be Empty";
                txtName.Focus();
            }
            else if (ddlAirLine.Text.Equals("None") == true)
            {
                lblError.Text = "Select Airline Name";
                ddlAirLine.Focus();
            }
            else
            {
                string flightName  = txtName.Text;
                int    airlineid   = int.Parse(ddlAirLine.SelectedItem.Value);
                string airlinename = ddlAirLine.SelectedItem.Text;
                Flight _flight     = new Flight()
                {
                    Name = flightName, AirlineForFlight = new Airline()
                    {
                        Id = airlineid, Name = airlinename
                    }
                };
                IFlightManager flightManager = (IFlightManager)AirTravelManagerFactory.Create("Flight");

                try
                {
                    foreach (RepeaterItem item in dlClass.Items)
                    {
                        TextBox txtNoOfSeats = (TextBox)item.FindControl("txtNoOfSeats");
                        Label   lblClass     = (Label)item.FindControl("lblClass");

                        if (txtNoOfSeats.Text.Length == 0)
                        {
                            txtNoOfSeats.Focus();
                            lblError.Text = "No of Seats Cannot be Empty";
                            break;
                        }
                        else
                        {
                            if (txtNoOfSeats != null)
                            {
                                TravelClass travelClass = (TravelClass)Enum.Parse(typeof(TravelClass), lblClass.Text.Trim());
                                int         NoOfSeats   = int.Parse(txtNoOfSeats.Text);
                                FlightClass _class      = new FlightClass()
                                {
                                    ClassInfo = travelClass, NoOfSeats = NoOfSeats
                                };
                                _flight.AddClass(_class);
                            }
                        }
                    }
                    if (flightManager.AddFlight(_flight) == false)
                    {
                        lblError.Text = "Flight Name already exists";
                    }
                    else
                    {
                        lblError.Text = "Flight Added Successfully";
                    }
                }
                catch (FlightManagerException exc)
                {
                    throw exc;
                }
            }
        }
示例#7
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                if (string.IsNullOrWhiteSpace(txtName.Text))
                {
                    ctlAdminMaster.ErrorMessage = "Flight Name Can't be Empty";
                    txtName.Focus();
                }
                else if (ddlAirLine.Text.Equals("None") == true)
                {
                    ctlAdminMaster.ErrorMessage = "Select Airline Name";
                    ddlAirLine.Focus();
                }
                else
                {
                    string flightName  = txtName.Text;
                    int    airlineid   = int.Parse(ddlAirLine.SelectedItem.Value);
                    string airlinename = ddlAirLine.SelectedItem.Text;
                    Flight _flight     = new Flight()
                    {
                        Name = flightName, AirlineForFlight = new Airline()
                        {
                            Id = airlineid, Name = airlinename
                        }
                    };
                    IFlightManager flightManager = (IFlightManager)AirTravelManagerFactory.Create("FlightManager");
                    bool           blnSeatsValid = true;

                    try
                    {
                        foreach (RepeaterItem item in dlClass.Items)
                        {
                            TextBox txtNoOfSeats     = (TextBox)item.FindControl("txtNoOfSeats");
                            Label   lblClass         = (Label)item.FindControl("lblClass");
                            int     intNumberOfSeats = 0;

                            if ((!int.TryParse(txtNoOfSeats.Text, out intNumberOfSeats)) || (intNumberOfSeats <= 0))
                            {
                                txtNoOfSeats.Focus();
                                ctlAdminMaster.ErrorMessage = "Seat count should be a positive number";
                                blnSeatsValid = false;
                                break;
                            }
                            else
                            {
                                if (txtNoOfSeats != null)
                                {
                                    TravelClass travelClass = (TravelClass)Enum.Parse(typeof(TravelClass), lblClass.Text.Trim());
                                    FlightClass _class      = new FlightClass()
                                    {
                                        ClassInfo = travelClass, NoOfSeats = intNumberOfSeats
                                    };
                                    _flight.AddClass(_class);
                                }
                            }
                        }
                        if (blnSeatsValid)
                        {
                            if (flightManager.AddFlight(_flight) == false)
                            {
                                ctlAdminMaster.ErrorMessage = "Flight Name already exists";
                            }
                            else
                            {
                                ctlAdminMaster.ErrorMessage = "Flight Added Successfully";
                            }
                        }
                    }
                    catch (FlightManagerException exc)
                    {
                        ctlAdminMaster.ErrorMessage = exc.Message;
                    }
                }
            }
        }