public static IQueryable <Room> AvailableForBooking(this IQueryable <Room> query,
                                                            string userId,
                                                            IQueryable <Booking> bookingQuery,
                                                            DateTime date, TimeSpan fromTime, TimeSpan toTime, int numOfPeople)
        {
            var now = DateTime.UtcNow;
            //empty room
            var notAvailableRoom = bookingQuery.ActiveStatus()
                                   .Overlapped(date, fromTime, toTime)
                                   .Select(b => b.Room);

            return(query = query.Except(notAvailableRoom)
                           .Available(true)
                           .InActiveTime(fromTime, toTime)
                           //not hanging by someone else
                           .NotHangingExcept(now, userId)
                           .CanHandle(numOfPeople));
        }
        public static async Task <IQueryable <Room> > FilterAsync(this IQueryable <Room> query, RoomQueryFilter model,
                                                                  string userId,
                                                                  IDictionary <string, object> tempData, IQueryable <Booking> bookingQuery)
        {
            var available = model.is_available ?? BoolOptions.B;

            if (available != BoolOptions.B)
            {
                query = query.Available(available == BoolOptions.T);
            }
            var archived = model.archived ?? BoolOptions.F;

            if (archived != BoolOptions.B)
            {
                query = query.Archived(!(archived == BoolOptions.F));
            }
            if (model.code != null)
            {
                query = query.Code(model.code);
            }
            if (model.name_contains != null)
            {
                query = query.NameContains(model.name_contains);
            }
            if (model.room_type != null)
            {
                query = query.OfRoomType(model.room_type);
            }
            if (model.num_of_people != null)
            {
                query = query.CanHandle(model.num_of_people.Value);
            }
            if (model.search != null)
            {
                query = query.Search(model.search);
            }
            if (model.empty)
            {
                //required fields
                var now = DateTime.UtcNow;
                var notAvailableRoomCode = bookingQuery.ActiveStatus()
                                           .Overlapped(model.date.Value, model.from_time.Value, model.to_time.Value)
                                           .Select(b => b.RoomCode).ToList();
                var dateLocal           = model.date.Value.ToDefaultTimeZone();
                var fapBookedRoomInDate = await Global.FapClient.GetFAPScheduleInDateRangeAsync(
                    dateLocal, dateLocal);

                var fapNotAvailableRoom = fapBookedRoomInDate.AsQueryable()
                                          .ActiveStatus()
                                          .Overlapped(model.date.Value, model.from_time.Value, model.to_time.Value)
                                          .Select(b => b.RoomCode).ToList();
                notAvailableRoomCode = notAvailableRoomCode.Union(fapNotAvailableRoom).ToList();
                query = query.ExceptCodes(notAvailableRoomCode)
                        .InActiveTime(model.from_time.Value, model.to_time.Value)
                        //not hanging by someone else
                        .NotHangingExcept(now, userId);

                //Already filter below
                //.Where(o => o.RoomTypeCode == model.room_type)
                //.Where(o => o.PeopleCapacity >= model.num_of_people);
            }
            return(query);
        }