Beispiel #1
0
 public IActionResult ArchiveFilter(AllFlightsViewModel model)
 {
     FlightFilteringAndPaging.ClearFilter();
     FlightFilteringAndPaging.FilterType = model.FilterType;
     FlightFilteringAndPaging.Filter     = model.Filter;
     return(View("FlightsArchive", GetFlightsArchive()));
 }
Beispiel #2
0
 public IActionResult FlightsFilter(AllFlightsViewModel model)
 {
     FlightFilteringAndPaging.ClearFilter();
     FlightFilteringAndPaging.FilterType = model.FilterType;
     FlightFilteringAndPaging.Filter     = model.Filter;
     return(View("Flights", GetAllUpcomingFlights()));
 }
Beispiel #3
0
        public AllFlightsViewModel GetFlightsArchive(bool hasBeenRedirected = false)
        {
            if (hasBeenRedirected)
            {
                FlightFilteringAndPaging.Clear();
            }

            List <Flight> validFlights = context.Flights.Where(x => x.Departure <= DateTime.Now).ToList();

            if (FlightFilteringAndPaging.FilterType != FlightFilterType.None)
            {
                string filter = FlightFilteringAndPaging.Filter;
                switch (FlightFilteringAndPaging.FilterType)
                {
                case FlightFilterType.From:
                    validFlights = validFlights.Where(flight => flight.From.Contains(filter)).ToList();
                    break;

                case FlightFilterType.To:
                    validFlights = validFlights.Where(flight => flight.To.Contains(filter)).ToList();
                    break;
                }
            }

            var pageFlights = validFlights
                              .Skip((FlightFilteringAndPaging.Pager.CurrentPage - 1) * FlightFilteringAndPaging.Pager.PageSize)
                              .Take(FlightFilteringAndPaging.Pager.PageSize).ToList();

            List <SingleFlightViewModel> flightsWithAppropriateData = new List <SingleFlightViewModel>();

            foreach (var singleFlight in pageFlights)
            {
                SingleFlightViewModel flight = new SingleFlightViewModel()
                {
                    Id        = singleFlight.Id,
                    From      = singleFlight.From,
                    To        = singleFlight.To,
                    Departure = singleFlight.Departure,
                    Duration  = singleFlight.Arrival - singleFlight.Departure
                };
                flightsWithAppropriateData.Add(flight);
            }


            flightsWithAppropriateData = flightsWithAppropriateData.OrderByDescending(x => x.Departure).ToList();
            AllFlightsViewModel model = new AllFlightsViewModel()
            {
                allFlights = flightsWithAppropriateData
            };

            FlightFilteringAndPaging.Pager.PagesCount = (int)Math.Ceiling(validFlights.Count() / (double)FlightFilteringAndPaging.Pager.PageSize);

            return(model);
        }
Beispiel #4
0
 public IActionResult ClearArchiveFilter()
 {
     FlightFilteringAndPaging.ClearFilter();
     return(View("FlightsArchive", GetFlightsArchive()));
 }
Beispiel #5
0
 public IActionResult ClearFlightsFilter()
 {
     FlightFilteringAndPaging.ClearFilter();
     return(View("Flights", GetAllUpcomingFlights()));
 }