//Get the List of Rooms with either open luggage or open space on that day public List <Rooms> GetAvailableRooms(DateTime checkinDate) { BookingHandler.CreateRooms(); BookingHandler.CreateFakeBooking(); List <Rooms> availableroomList = new List <Rooms>(); List <int> potentialrooomList = new List <int>(); //see if there is space in booked rooms foreach (RoomBooking rb in roomBookings) { Rooms availableroom = new Rooms(); bool isRoomOrLuggageSpaceAvailable = false; if (rb.CheckinTime.Date <= checkinDate.Date && checkinDate.Date < rb.CheckoutTime.Date) { potentialrooomList.Add(rb.RoomNumber); int roomCapacity = CheckifBookingHasSpaceforPerson(rb.NumberofPPl, rb.RoomNumber); int luggageCapacity = CheckifBookingHasSpaceforLuggage(rb.LuggageCount, rb.RoomNumber); if (roomCapacity > 0) { List <int> getGnomeSchedule = GetGnomeSchedule(1, checkinDate); if (getGnomeSchedule.Contains(rb.RoomNumber)) { availableroom.RoomNumber = rb.RoomNumber; availableroom.RoomCapacity = roomCapacity; isRoomOrLuggageSpaceAvailable = true; } } if (luggageCapacity > 0) //No need to check gnome's cleaning schedule here { availableroom.RoomNumber = rb.RoomNumber; availableroom.LuggageCount = luggageCapacity; isRoomOrLuggageSpaceAvailable = true; } } if (isRoomOrLuggageSpaceAvailable) { availableroomList.Add(availableroom); } } if (potentialrooomList.Count != roomList.Count) // there are some unbooked rooms here, those are available for that date { foreach (Rooms room in roomList) { if (!potentialrooomList.Contains(room.RoomNumber)) { availableroomList.Add(room); } } } return(availableroomList); }
public List <int> GetBookingRooms(int peopleCount, DateTime checkinDate, DateTime checkOutDate, int luggageCount) { List <int> vacantroomList = new List <int>(); if (checkinDate.Date < DateTime.Now.Date || checkOutDate.Date < DateTime.Now.Date || checkOutDate < checkinDate) //compare dates if trying to book in the past throw error { vacantroomList.Add(-3); } if (peopleCount == 1 && luggageCount > 2) // max number of luggages person is just 2 { vacantroomList.Add(-1); } int orginalNumberofppl = peopleCount; List <int> potentialRoomList = new List <int>(); BookingHandler.CreateRooms(); BookingHandler.CreateFakeBooking(); if (vacantroomList.Count == 0) { if (peopleCount <= GetMaxNumberofPplInInn() && luggageCount <= GetMaxNumberofLuggagesInInn()) { // Check if space is available in booked rooms foreach (RoomBooking rb in roomBookings) { int roomCapacity = CheckifBookingHasSpaceforPerson(rb.NumberofPPl, rb.RoomNumber); int luggageCapacity = CheckifRoomHasSpaceforLuggage(rb.LuggageCount, rb.RoomNumber); if (rb.CheckinTime.Date <= checkinDate.Date && checkinDate.Date < rb.CheckoutTime.Date && roomCapacity >= peopleCount && luggageCapacity >= luggageCount) { potentialRoomList.Add(rb.RoomNumber); List <int> getGnomeSchedule = GetGnomeSchedule(1, checkinDate.Date); if (getGnomeSchedule.Contains(rb.RoomNumber)) { vacantroomList.Add(rb.RoomNumber); } } } //Inn is empty, get available rooms , or the person coud nor fit in any room booking while (peopleCount > 0) { foreach (Rooms rm in roomList) { if (!potentialRoomList.Contains(rm.RoomNumber) && (!vacantroomList.Contains(rm.RoomNumber))) { if (orginalNumberofppl != 1 && rm.LuggageCount != 0 && rm.LuggageCount < luggageCount) { luggageCount = luggageCount - rm.LuggageCount; if (peopleCount == rm.RoomCapacity) { peopleCount = peopleCount - rm.LuggageCount; } else if (peopleCount > rm.RoomCapacity) { peopleCount = peopleCount - rm.RoomCapacity; } else if (peopleCount < rm.RoomCapacity) { peopleCount = rm.RoomCapacity - peopleCount; } vacantroomList.Add(rm.RoomNumber); } else if ((rm.LuggageCount != 0 && rm.LuggageCount > luggageCount) || (rm.LuggageCount == luggageCount)) { luggageCount = luggageCount - rm.LuggageCount; if (peopleCount == rm.RoomCapacity) { peopleCount = 0; } else { peopleCount = peopleCount - rm.RoomCapacity; } vacantroomList.Add(rm.RoomNumber); } if (peopleCount <= 0 && luggageCount <= 0) { return(vacantroomList); } if (peopleCount <= 0 && luggageCount >= 0) { vacantroomList.Clear(); vacantroomList.Add(-1); return(vacantroomList); } } } } } else //exceeds inn capacity { vacantroomList.Add(-2); } } return(vacantroomList); }