Exemplo n.º 1
0
        private static IQueryable <Booking> AddFiltersOnQuery(GetAllBookingsFilter filter, IQueryable <Booking> bookings)
        {
            if (filter?.PropertyId > 0)
            {
                bookings = bookings.Where(x => x.PropertyId == filter.PropertyId);
            }
            if (filter?.UserId > 0)
            {
                bookings = bookings.Where(x => x.UserId == filter.UserId);
            }
            if (filter?.BookingState != null)
            {
                bookings = bookings.Where(x => x.BookingState == filter.BookingState);
            }
            if (filter?.CheckInDate != null)
            {
                bookings = bookings.Where(x => x.CheckInDate >= filter.CheckInDate);
            }
            if (filter?.CheckOutDate != null)
            {
                bookings = bookings.Where(x => x.CheckOutDate <= filter.CheckOutDate);
            }

            return(bookings);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Booking> > GetAllBookingsAsync(GetAllBookingsFilter filter)
        {
            var bookings = _dataContext.Bookings.AsQueryable();

            bookings = AddFiltersOnQuery(filter, bookings);

            return(await bookings.ToListAsync());
        }