public RoomType GetNextAvailableConsultationRoom(Conference conference) { var roomType = conference.GetAvailableConsultationRoom(); var reservationKey = $"{conference.Id}:{roomType}"; // If not in cache, add to cache and return room if (!CheckIfRoomReserved(reservationKey, roomType)) { _logger.LogDebug("Using room {roomType} for consultation in conference {conference.Id}", roomType, conference.Id); return(roomType); } // Else return next room type if (roomType == RoomType.ConsultationRoom1) { roomType = RoomType.ConsultationRoom2; reservationKey = $"{conference.Id}:{roomType}"; if (!CheckIfRoomReserved(reservationKey, roomType)) { _logger.LogDebug("Using room {roomType} for consultation in conference {conference.Id}", roomType, conference.Id); return(roomType); } } throw new DomainRuleException("Unavailable room", "No consultation rooms available"); }