Exemple #1
0
        public async Task <ActionResult <IEnumerable <Booking> > > GetAllBookings([FromQuery] BookingQueryParameters parameters)
        {
            var bookings = await _repository.GetAllAsync(parameters);

            var metadata = new
            {
                ((PaginatedList <Booking>)bookings).ItemCount,
                ((PaginatedList <Booking>)bookings).PageSize,
                ((PaginatedList <Booking>)bookings).PageIndex,
                ((PaginatedList <Booking>)bookings).TotalPages,
                ((PaginatedList <Booking>)bookings).HasNextPage,
                ((PaginatedList <Booking>)bookings).HasPreviousPage
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            return(Ok(_mapper.Map <IEnumerable <BookingReadDto> >(bookings)));
        }
        public async Task <IActionResult> GetAllBookings([FromQuery] BookingQueryParameters queryParameters)
        {
            IQueryable <Booking> bookings = _context.Bookings;

            if (queryParameters.MinPrice != null && queryParameters.MaxPrice != null)
            {
                bookings = bookings.Where(b => b.Price >= queryParameters.MinPrice.Value && b.Price <= queryParameters.MaxPrice.Value);
            }

            if (!string.IsNullOrEmpty(queryParameters.BookingType))
            {
                bookings = bookings.Where(b => b.BookingType == queryParameters.BookingType);
            }


            bookings = bookings.Skip(queryParameters.Size * queryParameters.Page - 1)
                       .Take(queryParameters.Size);

            return(Ok(await bookings.ToArrayAsync()));
        }