Exemplo n.º 1
0
        public ActionResult FlightAdd(List <Flight> newFlights)
        {
            //init validation variables
            bool          invalid = false, invalid2 = false;
            int           total = newFlights.Count;
            List <string> added = new List <string>();

            ModelState.Remove("AvailSeatsF");
            ModelState.Remove("AvailSeatsE");
            ModelState.Remove("AvailSeatsB");
            ModelState.Remove("FlightTime");
            if (ModelState.IsValid)
            {
                foreach (var item in newFlights)
                {
                    //get aircraft of route
                    var route    = RouteDAO.GetRoute(item.RNo);
                    var aircraft = RouteDAO.GetAircraft(route.RAircraft);

                    //assign default seatnumbers
                    if (aircraft.FirstClassSeats != null)
                    {
                        item.AvailSeatsF = aircraft.FirstClassSeats;
                    }
                    if (aircraft.BussinessSeats != null)
                    {
                        item.AvailSeatsB = aircraft.BussinessSeats;
                    }
                    item.AvailSeatsE = aircraft.EconomySeats;
                    var diff = item.ArrivalTime.Hour - item.DepartureTime.Hour;
                    item.FlightTime = int.Parse(diff.ToString());
                    if (!FlightDAO.AddFlight(item))
                    {
                        ModelState.AddModelError("", string.Format("Could not add flight {0}", item.FNo));
                        invalid = true;
                        total--;
                    }
                    else
                    {
                        added.Add(string.Format("{0}", item.FNo));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Please enter required fields");
                invalid2 = true;
            }
            if (!invalid && !invalid2)
            {
                return(RedirectToAction("Flight"));
            }

            if (added.Count > 0)
            {
                ModelState.AddModelError("", "Flights Added: ");
                foreach (var item in added)
                {
                    ModelState.AddModelError("", item);
                }
            }

            return(View());
        }
Exemplo n.º 2
0
        //===Get aircraft range for route adding===
        public int GetAircraftRange(string id)
        {
            var a = RouteDAO.GetAircraft(id);

            return(a.Range);
        }