public IActionResult Index(string searchString, int?page, int pageSize = 10)
        {
            int pageNumber = (page ?? 1);
            FlightsIndexViewModel model = new FlightsIndexViewModel()
            {
                Flights = flightService.GetAllFlights().Select(f => new FlightIndexViewModel()
                {
                    FlightId              = f.Id,
                    TravelTime            = f.Arrival.Subtract(f.Departure),
                    BusinessClassCapacity = f.BusinessClassCapacity,
                    PilotName             = f.PilotName,
                    DepartureCity         = f.LeavingFrom,
                    DepartureTime         = f.Departure,
                    DestinationCity       = f.GoingTo,
                    PlaneID       = f.PlaneId,
                    PlaneCapacity = f.PassengersCapacity,
                    PlaneType     = f.AirplaneType
                }).ToList(),
                PageNumber = pageNumber,
                PageSize   = pageSize,
                PagesCount = (int)Math.Ceiling(flightService.GetAllFlights().Count / (double)pageSize)
            };

            if (!String.IsNullOrEmpty(searchString))
            {
                model.Flights = model.Flights.Where(f => f.DepartureCity.Contains(searchString) || f.DestinationCity.Contains(searchString)).ToList();
            }

            model.Flights = model.Flights.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(FlightsIndexViewModel model)
        {
            model.Pager ??= new PagerViewModel();
            model.Pager.CurrentPage = model.Pager.CurrentPage <= 0 ? 1 : model.Pager.CurrentPage;

            List <FlightsViewModel> items = await context.Flights.Skip((model.Pager.CurrentPage - 1) *PAGE_SIZE).Take(PAGE_SIZE).Select(f => new FlightsViewModel()
            {
                Id                     = f.Id,
                StartLocation          = f.StartLocation,
                FinalLocation          = f.FinalLocation,
                TimeOfDepartment       = f.TimeOfDepartment,
                TimeOfLanding          = f.TimeOfLanding,
                TravelingTime          = Math.Round((f.TimeOfLanding - f.TimeOfDepartment).TotalHours, 2),
                PlaneType              = f.PlaneType,
                PlaneNumber            = f.PlaneNumber,
                PilotName              = f.PilotName,
                EconomyClassCapacity   = f.EconomyClassCapacity,
                BuissnessClassCapacity = f.BuissnessClassCapacity
            }).ToListAsync();

            model.Items            = items;
            model.Pager.PagesCount = (int)Math.Ceiling(await context.Flights.CountAsync() / (double)PAGE_SIZE);

            return(View("FlightsView", model));
        }
        //GET : Flight
        public async Task <IActionResult> Index(FlightsIndexViewModel model)
        {
            model.Pager ??= new PagerViewModel();
            model.Pager.CurrentPage = model.Pager.CurrentPage <= 0 ? 1 : model.Pager.CurrentPage;

            List <FlightsViewModel> items = await _context.Flights.Skip((model.Pager.CurrentPage - 1) *PageSize).Take(PageSize).Select(c => new FlightsViewModel()
            {
                LocationFrom            = c.LocationFrom,
                LocationTo              = c.LocationTo,
                Going                   = c.Going,
                Return                  = c.Return,
                TypeOfPlane             = c.TypeOfPlane,
                PlaneID                 = c.PlaneID,
                NameOfAviator           = c.NameOfAviator,
                CapacityOfEconomyClass  = c.CapacityOfEconomyClass,
                CapacityOfBusinessClass = c.CapacityOfBusinessClass
            }).ToListAsync();

            model.Items            = items;
            model.Pager.PagesCount = (int)Math.Ceiling(await _context.Flights.CountAsync() / (double)PageSize);

            return(View(model));
        }