Пример #1
0
        public async Task <IEnumerable <Passenger> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Passenger> passengersIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var search = queryStringParameters.SearchString;
                passengersIq = _context.Passengers.Where(p => p.PassportNumber == search ||
                                                         p.Citizenship == search ||
                                                         p.Surname == search ||
                                                         p.Name == search)
                               .Include(passenger => passenger.Booking)
                               .ThenInclude(booking => booking.Customer)
                               .Include(passenger => passenger.Seat)
                               .AsNoTracking();
            }
            else
            {
                passengersIq = from b in _context.Passengers
                               .Include(passenger => passenger.Booking)
                               .ThenInclude(booking => booking.Customer)
                               .Include(passenger => passenger.Seat)
                               .AsNoTracking() select b;
            }

            // page
            IEnumerable <Passenger> passengers =
                await PaginatedList <Passenger> .CreateAsync(passengersIq, queryStringParameters.PageNumber,
                                                             queryStringParameters.PageSize);


            // sort string not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(passengers);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Passenger>)passengers).ItemCount;
            var index = ((PaginatedList <Passenger>)passengers).PageIndex;
            var size  = ((PaginatedList <Passenger>)passengers).PageSize;

            passengers = sort switch
            {
                "name_desc" => passengers.OrderByDescending(p => p.Name),
                "surname" => passengers.OrderBy(p => p.Surname),
                "surname_desc" => passengers.OrderByDescending(p => p.Surname),
                "passport" => passengers.OrderBy(p => p.PassportNumber),
                "passport_desc" => passengers.OrderByDescending(p => p.PassportNumber),
                _ => passengers.OrderBy(p => p.Name)
            };

            return(PaginatedList <Passenger> .ParsePaginatedList(passengers, count, index, size));
        }
Пример #2
0
        public async Task <IEnumerable <Booking> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Booking> bookingsIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var search = queryStringParameters.SearchString;
                // search by date
                bookingsIq = _context.Bookings
                             .Where(b => b.TimeStamp == DateTime.Parse(search))
                             .Include(booking => booking.Passengers)
                             .ThenInclude(passenger => passenger.Seat)
                             .Include(b => b.Customer)
                             .AsNoTracking();
            }
            else
            {
                bookingsIq = from b in _context.Bookings
                             .Include(booking => booking.Passengers)
                             .ThenInclude(passenger => passenger.Seat)
                             .Include(b => b.Customer)
                             .AsNoTracking()
                             select b;
            }

            // page
            IEnumerable <Booking> bookings =
                await PaginatedList <Booking> .CreateAsync(bookingsIq, queryStringParameters.PageNumber, queryStringParameters.PageSize);


            // sort string not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(bookings);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Booking>)bookings).ItemCount;
            var index = ((PaginatedList <Booking>)bookings).PageIndex;
            var size  = ((PaginatedList <Booking>)bookings).PageSize;

            bookings = sort switch
            {
                "timestamp_desc" => bookings.OrderByDescending(b => b.TimeStamp),
                "cost" => bookings.OrderBy(b => b.Cost),
                "cost_desc" => bookings.OrderByDescending(b => b.Cost),
                _ => bookings.OrderBy(b => b.TimeStamp)
            };

            return(PaginatedList <Booking> .ParsePaginatedList(bookings, count, index, size));
        }
Пример #3
0
        public async Task <IEnumerable <Flight> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Flight> flightsIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var search = queryStringParameters.SearchString;
                flightsIq = _context.Flights
                            .Where(f => f.Name.ToUpper().Contains(search.ToUpper()) || f.Description.ToUpper().Contains(search.ToUpper()))
                            .Include(f => f.Departure)
                            .ThenInclude(departure => departure.Airport)
                            .Include(f => f.Destination)
                            .ThenInclude(destination => destination.Airport)
                            .AsNoTracking();
            }
            else
            {
                flightsIq = from f in _context.Flights
                            .Include(f => f.Departure)
                            .ThenInclude(departure => departure.Airport)
                            .Include(f => f.Destination)
                            .ThenInclude(destination => destination.Airport)
                            .AsNoTracking()
                            select f;
            }

            // page
            IEnumerable <Flight> flights =
                await PaginatedList <Flight> .CreateAsync(flightsIq, queryStringParameters.PageNumber, queryStringParameters.PageSize);


            // sort string not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(flights);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Flight>)flights).ItemCount;
            var index = ((PaginatedList <Flight>)flights).PageIndex;
            var size  = ((PaginatedList <Flight>)flights).PageSize;

            flights = sort switch
            {
                "name_desc" => flights.OrderByDescending(f => f.Name),
                _ => flights.OrderBy(f => f.Name)
            };

            return(PaginatedList <Flight> .ParsePaginatedList(flights, count, index, size));
        }
Пример #4
0
        public async Task <IEnumerable <Customer> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Customer> customersIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var search = queryStringParameters.SearchString;
                // search by date
                customersIq = _context.Customers
                              .Where(c => c.Name == search || c.Email == search)
                              .Include(customer => customer.Bookings)
                              .ThenInclude(booking => booking.Passengers)
                              .AsNoTracking();
            }
            else
            {
                customersIq = from c in _context.Customers
                              .Include(customer => customer.Bookings)
                              .ThenInclude(booking => booking.Passengers)
                              .AsNoTracking()
                              select c;
            }

            // page
            IEnumerable <Customer> customers =
                await PaginatedList <Customer> .CreateAsync(customersIq, queryStringParameters.PageNumber,
                                                            queryStringParameters.PageSize);


            // sort string not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(customers);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Customer>)customers).ItemCount;
            var index = ((PaginatedList <Customer>)customers).PageIndex;
            var size  = ((PaginatedList <Customer>)customers).PageSize;

            customers = sort switch
            {
                "name_desc" => customers.OrderByDescending(c => c.Name),
                "email" => customers.OrderBy(c => c.Email),
                "email_desc" => customers.OrderByDescending(c => c.Email),
                _ => customers.OrderBy(c => c.Name)
            };

            return(PaginatedList <Customer> .ParsePaginatedList(customers, count, index, size));
        }
Пример #5
0
        public async Task <IEnumerable <Departure> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Departure> departuresIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var searchDate = DateTime.Parse(queryStringParameters.SearchString);
                departuresIq = _context.Departures
                               .Where(d => d.Date.Equals(searchDate))
                               .Include(dep => dep.Airport)
                               .AsNoTracking();
            }
            else
            {
                departuresIq = from d in _context.Departures
                               .Include(dep => dep.Airport)
                               .AsNoTracking()
                               select d;
            }

            // page
            IEnumerable <Departure> departures =
                await PaginatedList <Departure> .CreateAsync(departuresIq, queryStringParameters.PageNumber, queryStringParameters.PageSize);

            // sort - not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(departures);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Departure>)departures).ItemCount;
            var index = ((PaginatedList <Departure>)departures).PageIndex;
            var size  = ((PaginatedList <Departure>)departures).PageSize;

            departures = sort switch
            {
                "date_desc" => departures.OrderByDescending(d => d.Date),
                "flight" => departures.OrderBy(d => d.FlightId),
                "flight_desc" => departures.OrderBy(d => d.FlightId),
                "airport" => departures.OrderByDescending(d => d.AirportId),
                "airport_desc" => departures.OrderByDescending(d => d.AirportId),
                _ => departures.OrderBy(d => d.Date)
            };

            return(PaginatedList <Departure> .ParsePaginatedList(departures, count, index, size));
        }
Пример #6
0
        public async Task <IEnumerable <Airport> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Airport> airportsIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var searchString = queryStringParameters.SearchString;
                airportsIq = _context.Airports.Where(a => a.Name.ToUpper().Contains(searchString.ToUpper()) ||
                                                     a.Country.ToUpper().Contains(searchString.ToUpper()) ||
                                                     a.City.ToUpper().Contains(searchString.ToUpper()));
            }
            else
            {
                airportsIq = from a in _context.Airports select a;
            }

            // page
            IEnumerable <Airport> airports =
                await PaginatedList <Airport> .CreateAsync(airportsIq, queryStringParameters.PageNumber, queryStringParameters.PageSize);

            // sort string not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(airports);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Airport>)airports).ItemCount;
            var index = ((PaginatedList <Airport>)airports).PageIndex;
            var size  = ((PaginatedList <Airport>)airports).PageSize;

            airports = sort switch
            {
                "name_desc" => airports.OrderByDescending(a => a.Name),
                "country" => airports.OrderBy(a => a.Country),
                "country_desc" => airports.OrderByDescending(a => a.Country),
                "city" => airports.OrderBy(a => a.City),
                "city_desc" => airports.OrderByDescending(a => a.City),
                _ => airports.OrderBy(a => a.Name)
            };

            return(PaginatedList <Airport> .ParsePaginatedList(airports, count, index, size));
        }
Пример #7
0
        public async Task <IEnumerable <Seat> > GetAllAsync(QueryStringParameters queryStringParameters)
        {
            IQueryable <Seat> seatsIq;

            // search
            if (!string.IsNullOrEmpty(queryStringParameters.SearchString))
            {
                var search = queryStringParameters.SearchString;
                seatsIq = _context.Seats
                          .Where(s => s.SeatNum.ToUpper().Contains(search.ToUpper()));
            }
            else
            {
                seatsIq = from s in _context.Seats select s;
            }

            // page
            IEnumerable <Seat> seats =
                await PaginatedList <Seat> .CreateAsync(seatsIq, queryStringParameters.PageNumber, queryStringParameters.PageSize);


            // sort - string not set
            if (string.IsNullOrEmpty(queryStringParameters.SortString))
            {
                return(seats);
            }

            // sort
            var sort = queryStringParameters.SortString;

            var count = ((PaginatedList <Seat>)seats).ItemCount;
            var index = ((PaginatedList <Seat>)seats).PageIndex;
            var size  = ((PaginatedList <Seat>)seats).PageSize;

            seats = sort switch
            {
                "seat_desc" => seats.OrderByDescending(s => s.SeatNum),
                "cabin" => seats.OrderBy(s => s.Cabin),
                "cabin_desc" => seats.OrderByDescending(s => s.Cabin),
                _ => seats.OrderBy(s => s.SeatNum)
            };

            return(PaginatedList <Seat> .ParsePaginatedList(seats, count, index, size));
        }