コード例 #1
0
        // GET: FlightController
        public ActionResult Index()
        {
            ViewBag.IsLoggedIn = true;
            List <Flight>               flightsAll  = uow.Flight.GetAll();
            List <Pilot>                pilotsAll   = uow.Pilot.GetAll();
            List <Airlines>             airlinesAll = uow.Airlines.GetAll();
            FlightsWithAirlineWithPilot model       = new FlightsWithAirlineWithPilot
            {
                Flights  = flightsAll,
                Pilots   = pilotsAll,
                Airlines = airlinesAll
            };

            return(View(model));
        }
コード例 #2
0
        public ActionResult Search([FromForm] SearchFlightsViewModel m)
        {
            List <Airlines> airlinesAll = uow.Airlines.GetAll();
            List <Pilot>    pilotsAll   = uow.Pilot.GetAll();
            List <Flight>   flightsAll  = uow.Flight.GetAll();
            Flight          f1          = uow.Flight.FindById(m.startID);
            String          start       = f1.StartDestination;
            Flight          f2          = uow.Flight.FindById(m.endID);
            String          end         = f2.EndDestination;
            DateTime        onlyDate    = m.Date.Date;

            List <Flight> flightsSearched = new List <Flight>();

            foreach (Flight flight in flightsAll)
            {
                if (flight.Date.Date == onlyDate && flight.StartDestination == start && flight.EndDestination == end)
                {
                    flightsSearched.Add(new Flight
                    {
                        StartDestination  = flight.StartDestination,
                        EndDestination    = flight.EndDestination,
                        Date              = flight.Date,
                        DurationInMinutes = flight.DurationInMinutes,
                        PilotID           = flight.PilotID,
                        Price             = flight.Price
                    }
                                        );
                }
            }
            if (flightsSearched.Count == 0)
            {
            }
            FlightsWithAirlineWithPilot model = new FlightsWithAirlineWithPilot
            {
                Flights  = flightsSearched,
                Airlines = airlinesAll,
                Pilots   = pilotsAll
            };

            return(View("SearchFlights", model));
        }