/// <summary> /// Get list card attachment having list of favorite rooms along with buttons to manage favorites, book meeting for other rooms and refresh list. /// </summary> /// <param name="rooms">Rooms schedule response object.</param> /// <param name="startUTCDateTime">Start date time of meeting.</param> /// <param name="endUTCDateTime">End date time of meeting.</param> /// <param name="timeZone">User time zone.</param> /// <param name="activityReferenceId">Unique GUID related to activity Id from ActivityEntities table.</param> /// <returns>List card attachment having favorite rooms of user.</returns> public static Attachment GetFavoriteRoomsListAttachment(RoomScheduleResponse rooms, DateTime startUTCDateTime, DateTime endUTCDateTime, string timeZone, string activityReferenceId = null) { ListCard card = new ListCard { Title = Strings.RoomAvailability, Items = new List <ListItem>(), Buttons = new List <CardAction>(), }; // For first run, user configuration will be null. if (timeZone != null) { var startTime = TimeZoneInfo.ConvertTimeFromUtc(startUTCDateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZone)); var endTime = TimeZoneInfo.ConvertTimeFromUtc(endUTCDateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZone)); card.Title = string.Format(CultureInfo.CurrentCulture, "{0} | {1} - {2}", Strings.RoomAvailability, startTime.ToString("t", CultureInfo.CurrentCulture), endTime.ToString("t", CultureInfo.CurrentCulture)); } ListItem room = new ListItem(); Meeting meeting; if (rooms?.Schedules.Count > 0) { foreach (var item in rooms.Schedules) { string availability; string availabilityColor; // Schedule will be null in case room is deleted from exchange but sync service still gets room from Graph API as Graph takes time to reflect deleted item. if (item.ScheduleItems != null && item.ScheduleItems.Count == 0) { availability = Strings.Available; availabilityColor = GreenColorCode; } else { availability = Strings.Unavailable; availabilityColor = RedColorCode; } var subtitle = string.Format(CultureInfo.CurrentCulture, "{0} | <b><font color='{1}'>{2}</font></b>", item.BuildingName, availabilityColor, availability); meeting = new Meeting { EndDateTime = DateTime.SpecifyKind(endUTCDateTime, DateTimeKind.Utc).ToString("o"), RoomEmail = item.ScheduleId, RoomName = item.RoomName, StartDateTime = DateTime.SpecifyKind(startUTCDateTime, DateTimeKind.Utc).ToString("o"), BuildingName = item.BuildingName, Status = availability, Text = BotCommands.CreateMeeting, }; card.Items.Add(new ListItem { Id = item.ScheduleId, Title = item.RoomName, Subtitle = subtitle, Type = "person", Tap = new CardAction { Type = ActionTypes.MessageBack, Text = BotCommands.CreateMeeting, Title = BotCommands.CreateMeeting, Value = JsonConvert.SerializeObject(meeting) }, }); } } else { room = new ListItem { Title = Strings.NoFavoriteRooms, Type = "section", }; } card.Items.Add(room); CardAction addFavoriteButton = new TaskModuleAction(Strings.ManageFavorites, new { data = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction { Text = BotCommands.ShowFavoriteTaskModule, ActivityReferenceId = activityReferenceId }) }); card.Buttons.Add(addFavoriteButton); CardAction otherRoomButton = new TaskModuleAction(Strings.OtherRooms, new { data = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction { Text = BotCommands.ShowOtherRoomsTaskModule, ActivityReferenceId = activityReferenceId }) }); card.Buttons.Add(otherRoomButton); CardAction bookRoomNowButton = new TaskModuleAction(Strings.BookRoomNow, new { data = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction { Text = BotCommands.BookAMeetingNow, ActivityReferenceId = activityReferenceId }) }); card.Buttons.Add(bookRoomNowButton); if (rooms?.Schedules.Count > 0) { CardAction refreshListButton = new CardAction { Title = Strings.Refresh, Type = ActionTypes.MessageBack, Text = BotCommands.RefreshList, Value = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction { Text = BotCommands.RefreshList, ActivityReferenceId = activityReferenceId }), }; card.Buttons.Add(refreshListButton); } var attachment = new Attachment() { ContentType = "application/vnd.microsoft.teams.card.list", Content = card, }; return(attachment); }