public async Task <Dictionary <string, Tuple <RoomInfo, IRoom> > > GetInfoForRoomsInBuilding(string buildingId) { // repo data var roomMetadatasTask = _roomRepository.GetRoomInfosForBuildingAsync(buildingId); var buildingTask = _buildingRepository.GetAsync(buildingId); var floorsTask = _floorRepository.GetAllByBuildingAsync(buildingId); var roomMetadatas = (await roomMetadatasTask).ToDictionary(_ => _.RoomAddress); // get these started in parallel while we load data from the repositories var roomTasks = roomMetadatas.ToDictionary(i => i.Key, i => GetRoomName(i.Key)).ToList(); var building = await buildingTask; var floors = (await floorsTask).ToDictionary(_ => _.Id); __log.DebugFormat("Started room load calls"); // put it all together var results = new Dictionary <string, Tuple <RoomInfo, IRoom> >(); foreach (var kvp in roomTasks) { var roomAddress = kvp.Key; var room = await kvp.Value; if (null == room) { continue; } var roomMetadata = roomMetadatas.TryGetValue(roomAddress) ?? new RoomMetadataEntity(); var canControl = CanControl(roomMetadata); var floor = floors.TryGetValue(roomMetadata.FloorId) ?? new FloorEntity(); results.Add(roomAddress, new Tuple <RoomInfo, IRoom>(BuildRoomInfo(room, canControl, roomMetadata, building, floor), roomMetadata)); } __log.DebugFormat("Room info build complete"); return(results); }