public async Task <(bool, int)> TryBookARoomAsync(int startDate, int endDate)
        {
            var roomBookingInfos = _bookingDb.GetBookedDaysByRoom();

            if (!roomBookingInfos.Any()) //if there are no rooms, booking cannot be made
            {
                return(false, 0);
            }

            var firstAvailableRoomId = roomBookingInfos.FirstOrDefault(rbi => !rbi.BookedDays.Any(bd => bd >= startDate && bd <= endDate))?.Id;

            if (firstAvailableRoomId == null) //if there is no room available, booking cannot be made
            {
                return(false, 0);
            }


            //make the booking
            var newBooking = new Booking
            {
                RoomId    = firstAvailableRoomId.Value,
                StartDate = startDate,
                EndDate   = endDate
            };
            await _bookingDb.MakeNewBookingAsync(newBooking);

            return(true, firstAvailableRoomId.Value);
        }
Example #2
0
        public async Task TestCase1b()
        {
            var newBooking = new Booking
            {
                RoomId    = 1,
                StartDate = -4,
                EndDate   = 2
            };

            //var bookingId = await _bookingDb.MakeNewBookingAsync(newBooking);
            await _bookingDb.MakeNewBookingAsync(newBooking);

            //TODO:
            // - get booking by id
            Booking booking = null; //GetBookingById(bookingId)

            //if not found, OK
            Assert.IsNull(booking, "Booking shouldn't be made!");
        }