Exemplo n.º 1
0
        private List <HotelRoomQuantity> getAvailableRooms(string starting, string ending, string destination)
        {
            List <HotelRoomQuantity> tempHotels     = new List <HotelRoomQuantity>();
            List <HotelRoomQuantity> hotel_occupied = dbm.getHotelCapacityByDes(destination);

            //List<HotelRoomQuantity> hotel_occupied = Clone.cloneHotels(HotelCapacityFactory.getFactory().getHotelsByDestination(destination).getHotelCapacityByDestination());
            foreach (HotelRoomQuantity room in hotel_occupied)
            {
                room.Quantity = 0;
            }
            DateTime      ArrivalDate   = Convert.ToDateTime(starting);
            DateTime      DepartureDate = Convert.ToDateTime(ending);
            List <Object> list          = new List <Object>();

            for (DateTime i = ArrivalDate; i < DepartureDate; i = i.AddDays(1))
            {
                String date = i.ToShortDateString();
                list.Add(dbm.getReservedOnSingleNight(date, destination));
            }

            for (int i = 0; i < list.Count; i++)
            {
                foreach (HotelRoomQuantity hotel in hotel_occupied)
                {
                    foreach (HotelRoomQuantity reserved in (List <HotelRoomQuantity>)list[i])
                    {
                        if (hotel.H_name.Equals(reserved.H_name) && hotel.R_type.Equals(reserved.R_type))
                        {
                            if (hotel.Quantity < reserved.Quantity)
                            {
                                hotel.Quantity = reserved.Quantity;
                            }
                        }
                    }
                }
            }

            //List<HotelRoomQuantity> occupied = dbm.getReserved(starting, ending, destination);

            foreach (HotelRoomQuantity hotel in hotels)
            {
                hotel.TotalRooms = hotel.Quantity;

                foreach (HotelRoomQuantity reserved in hotel_occupied)
                {
                    if (hotel.H_name.Equals(reserved.H_name) && hotel.R_type.Equals(reserved.R_type))
                    {
                        hotel.Quantity -= reserved.Quantity;
                        if (hotel.Quantity > 0)
                        {
                            hotel.AvailableRooms = hotel.Quantity;
                            tempHotels.Add(hotel);
                        }
                    }
                }
            }

            return(tempHotels);
        }