private async Task GotRoomStatus(IDialogContext context, IAwaitable <RoomsService.RoomStatusResult[]> callback) { var rooms = await callback; var tz = GetTimezone(context.GetBuilding()?.BuildingId); var now = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, tz); if (_criteria.NumberOfPeople.HasValue) { if (rooms.Any(r => r.Info.Size > 0)) { rooms = rooms.Where(r => r.Info.Size >= _criteria.NumberOfPeople).ToArray(); } else { await context.PostAsync(context.CreateMessage($"Not checking room size - data not available for that building", InputHints.IgnoringInput)); } } var equiValues = (_criteria.Equipment ?? new List <RoomSearchCriteria.EquipmentOptions>()).Where(i => i != RoomSearchCriteria.EquipmentOptions.None).ToArray(); if (equiValues.Any()) { if (rooms.Any(r => (r.Info.Equipment ?? new List <RoomSearchCriteria.EquipmentOptions>()).Any())) { rooms = rooms.Where(r => equiValues.All(e => (r.Info.Equipment ?? new List <RoomSearchCriteria.EquipmentOptions>()).Contains(e))).ToArray(); } else { await context.PostAsync(context.CreateMessage($"Not checking room equipment - data not available for that building", InputHints.IgnoringInput)); } } var preferredFloorId = context.GetPreferredFloor()?.FloorId; // ok, now we just have rooms that meet the criteria - let's see what's free when asked _allRooms = rooms.ToList(); _roomResults = rooms.Select(r => { var meetings = r.Status.NearTermMeetings.Where(i => i.End > _criteria.StartTime).OrderBy(i => i.Start).ToList(); var firstMeeting = meetings.FirstOrDefault(); if (null == firstMeeting) { return(new { busy = false, room = r }); } else if (firstMeeting.Start > _criteria.EndTime && !firstMeeting.IsStarted) { return(new { busy = false, room = r }); } else { return(new { busy = true, room = r }); } }) .Where(i => !i.busy) .Select(i => i.room) .OrderBy(i => i.Info.FloorId == preferredFloorId ? 0 : 1) .ThenBy(i => i.Info.Size) .ThenBy(i => i.Info.Equipment?.Count) .ToList(); if (_roomResults.Count == 0) { await context.PostAsync(context.CreateMessage($"Sorry, no free rooms meet that criteria", InputHints.AcceptingInput)); context.Done(string.Empty); } else if (_roomResults.Count == 1) { await context.PostAsync(context.CreateMessage($"{_roomResults[0].Info.SpeakableName} is free - would you like to reserve it?", InputHints.ExpectingInput)); context.Wait(ConfirmBookOneRoom); } else { await PromptForMultipleRooms(context); } }