/// <summary> /// Handles event skip action. /// </summary> /// <param name="context">IDialogContext object.</param> /// <param name="activity">IAwaitable message activity.</param> /// <returns>Task.</returns> public async Task HandleEventSkipActions(IDialogContext context, IAwaitable <IMessageActivity> activity) { var message = (Activity)await activity; if (message.Value != null) { var replyMessage = string.Empty; var previewCardPayload = ((JObject)message.Value).ToObject <PreviewCardPayload>(); // Get event by eventId to check if it exist or not. CelebrationEvent celebrationEvent = await this.eventHelper.GetEventByEventIdAsync(previewCardPayload.EventId, previewCardPayload.OwnerAadObjectId); if (celebrationEvent != null) { if (previewCardPayload.UpcomingEventDate > DateTime.UtcNow.Date) { await this.eventHelper.UpdateRecurringEventAsync(previewCardPayload.EventId, EventStatus.Skipped); EventMessageActivity eventMessageActivity = new EventMessageActivity { Id = celebrationEvent.Id, OwnerName = previewCardPayload.OwnerName, ImageUrl = celebrationEvent.ImageURL, Message = celebrationEvent.Message, Title = celebrationEvent.Title, }; // Update the card IMessageActivity updatedMessage = context.MakeMessage(); updatedMessage.Attachments.Add(CelebrationCard.GetPreviewCard(eventMessageActivity, false).ToAttachment()); updatedMessage.ReplyToId = message.ReplyToId; await this.connectorClient.Conversations.UpdateActivityAsync(message.Conversation.Id, message.ReplyToId, (Activity)updatedMessage); replyMessage = string.Format(Strings.EventSkippedMessage, message.From.Name); } else { // event occurrence has already passed for current year. replyMessage = string.Format(Strings.EventPassedMessage); } } else { replyMessage = string.Format(Strings.EventNotExistMessage, previewCardPayload.Title); } await context.PostAsync(replyMessage); context.Done <object>(null); } }
/// <summary> /// Create and return CelebrationEvent card. /// </summary> /// <param name="eventMessageActivity">EventMessageActivity Instance.</param> /// <returns>HeroCard</returns> public static HeroCard GetEventCard(EventMessageActivity eventMessageActivity) { string imagePath = Common.GetImagePath(eventMessageActivity.ImageUrl); List <CardImage> cardImages = new List <CardImage>() { new CardImage(url: imagePath) }; HeroCard eventCard = new HeroCard() { Title = string.Format(Strings.EventCardTitle, eventMessageActivity.OwnerName, eventMessageActivity.Title) + "\n\n", Text = eventMessageActivity.Message, Images = cardImages, }; return(eventCard); }
/// <summary> /// Create and return preview card. /// </summary> /// <param name="eventMessageActivity">EventMessageActivity instance</param> /// <param name="isSkipAllowed">true/false</param> /// <returns>AdaptiveCard.</returns> public static HeroCard GetPreviewCard(EventMessageActivity eventMessageActivity, bool isSkipAllowed = true) { string imagePath = Common.GetImagePath(eventMessageActivity.ImageUrl); List <CardAction> cardActions = new List <CardAction>() { new CardAction() { Title = "Edit", Type = "openUrl", Value = new Uri(Common.GetDeepLinkUrlToEventsTab("EventsTab", "Tabs/Events", "{\"subEntityId\":\"" + eventMessageActivity.Id + "\"}")), }, }; if (isSkipAllowed) { cardActions.Insert(0, new CardAction() { Title = "Skip", Type = "invoke", Value = JObject.FromObject(new PreviewCardPayload { Action = "SkipEvent", EventId = eventMessageActivity.Id, OwnerAadObjectId = eventMessageActivity.OwnerAadObjectId, OwnerName = eventMessageActivity.OwnerName, Title = eventMessageActivity.Title, UpcomingEventDate = Common.GetUpcomingEventDate(eventMessageActivity.EventDate, DateTime.UtcNow.Date), }).ToString(), }); } HeroCard previewCard = new HeroCard() { Title = string.Format(Strings.PreviewHeader, eventMessageActivity.OwnerName, eventMessageActivity.Title) + "\n\n", Text = eventMessageActivity.Message, Buttons = cardActions, Images = new List <CardImage>() { new CardImage(url: imagePath) }, }; return(previewCard); }