Beispiel #1
0
        public IReadOnlyCollection <Hotel> Execute(IReadOnlyCollection <Hotel> input)
        {
            if (!roomRequirements.Exists())
            {
                return(input);
            }
            var filteredHotels = new List <Hotel>();

            foreach (var hotel in input)
            {
                var roomsSelectionPipeline = new RoomsSelectionPipeline();
                var roomsOfHotel           = rooms.Where(room => room.HotelId == hotel.Id).ToList();
                roomsSelectionPipeline
                .Register(new RoomPriceFromFilter(roomRequirements.PriceFrom))
                .Register(new RoomPriceToFilter(roomRequirements.PriceTo))
                .Register(new RoomCapacityFilter(roomRequirements.RequiredCapacity))
                .Register(
                    new RoomAvailabilityFilter(roomRequirements.CheckIn, roomRequirements.CheckOut, orders.ToList()));
                IEnumerable <Room> filteredRooms = roomsSelectionPipeline.Process(roomsOfHotel);
                if (filteredRooms != null && filteredRooms.Any())
                {
                    filteredHotels.Add(hotel);
                }
            }

            return(filteredHotels);
        }
Beispiel #2
0
        public IReadOnlyCollection <RoomData> SearchByFilter(RoomRequirements roomRequirements)
        {
            var roomsSelectionPipeline = new RoomsSelectionPipeline();

            roomsSelectionPipeline.Register(new RoomPriceFromFilter(roomRequirements.PriceFrom))
            .Register(new RoomPriceToFilter(roomRequirements.PriceTo))
            .Register(new RoomCapacityFilter(roomRequirements.RequiredCapacity))
            .Register(new RoomAvailabilityFilter(roomRequirements.CheckIn, roomRequirements.CheckOut, context.Orders.ToList()));
            return(Map(roomsSelectionPipeline.Process(context.Rooms.Where(room => room.HotelId == roomRequirements.HotelId)
                                                      .ToList())));
        }