/// <summary>
        /// Return the appropriate fact set based on the state and information in the ticket.
        /// </summary>
        /// <param name="data">User activity payload.</param>
        /// <param name="localTimestamp">The current timestamp.</param>
        /// <param name="userName">The user who sent the feeback.</param>
        /// <returns>The fact set showing the necessary details.</returns>
        private static List <AdaptiveFact> BuildFactSet(ShareFeedbackCardPayload data, DateTimeOffset?localTimestamp, string userName)
        {
            List <AdaptiveFact> factList = new List <AdaptiveFact>();

            if (string.IsNullOrEmpty(data.TicketId))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.QuestionMessageFeedbackText,
                    Value = data.UserQuestion,
                });
            }
            else
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.QuestionMessageFeedbackText,
                    Value = string.Format(CultureInfo.InvariantCulture, Strings.SMEFeedbackTicketIDFact, data.TicketId, data.UserQuestion),
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.RatingTitle,
                Value = GetRatingDisplayText(data?.Rating),
            });

            // Description fact is available in the card only when user enters description text.
            if (!string.IsNullOrWhiteSpace(data.Description))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.DescriptionText,
                    Value = CardHelper.TruncateStringIfLonger(data.Description, CardHelper.DescriptionMaxDisplayLength),
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.DateFactTitle,
                Value = CardHelper.GetFormattedDateInUserTimeZone(DateTime.Now, localTimestamp),
            });

            factList.Add(new AdaptiveFact
            {
                Title = Strings.ProvidedByFact,
                Value = userName,
            });

            return(factList);
        }
Exemple #2
0
        /// <summary>
        /// Building the fact set to render out the user facing details.
        /// </summary>
        /// <param name="ticket">The current ticket information.</param>
        /// <param name="activityLocalTimestamp">The local timestamp.</param>
        /// <returns>The adaptive facts.</returns>
        private List <AdaptiveFact> BuildFactSet(TicketEntity ticket, DateTimeOffset?activityLocalTimestamp)
        {
            List <AdaptiveFact> factList = new List <AdaptiveFact>();

            factList.Add(new AdaptiveFact
            {
                Title = Strings.StatusFactTitle,
                Value = CardHelper.GetUserTicketDisplayStatus(this.ticket),
            });

            factList.Add(new AdaptiveFact
            {
                Title = Strings.TitleFact,
                Value = CardHelper.TruncateStringIfLonger(this.ticket.Title, CardHelper.TitleMaxDisplayLength),
            });

            if (!string.IsNullOrEmpty(ticket.Description))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.DescriptionFact,
                    Value = CardHelper.TruncateStringIfLonger(this.ticket.Description, CardHelper.DescriptionMaxDisplayLength),
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.DateCreatedDisplayFactTitle,
                Value = CardHelper.GetFormattedDateInUserTimeZone(this.ticket.DateCreated, activityLocalTimestamp),
            });

            if (ticket.Status == (int)TicketState.Closed)
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.ClosedFactTitle,
                    Value = CardHelper.GetFormattedDateInUserTimeZone(this.ticket.DateClosed.Value, activityLocalTimestamp),
                });
            }

            return(factList);
        }
Exemple #3
0
        /// <summary>
        /// Return the appropriate fact set based on the state and information in the ticket.
        /// </summary>
        /// <param name="localTimestamp">The current timestamp.</param>
        /// <returns>The fact set showing the necessary details.</returns>
        private List <AdaptiveFact> BuildFactSet(DateTimeOffset?localTimestamp)
        {
            List <AdaptiveFact> factList = new List <AdaptiveFact>();

            if (!string.IsNullOrEmpty(this.Ticket.Description))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.DescriptionFact,
                    Value = this.Ticket.Description,
                });
            }

            if (!string.IsNullOrEmpty(this.Ticket.UserQuestion))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.QuestionAskedFactTitle,
                    Value = this.Ticket.UserQuestion,
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.StatusFactTitle,
                Value = CardHelper.GetTicketDisplayStatusForSme(this.Ticket),
            });

            if (this.Ticket.Status == (int)TicketState.Closed)
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.ClosedFactTitle,
                    Value = CardHelper.GetFormattedDateInUserTimeZone(this.Ticket.DateClosed.Value, localTimestamp),
                });
            }

            return(factList);
        }
        /// <summary>
        /// Building the fact set to render out the user facing details.
        /// </summary>
        /// <param name="ticket">The current ticket information.</param>
        /// <param name="activityLocalTimestamp">The local timestamp.</param>
        /// <returns>The adaptive facts.</returns>
        private List <AdaptiveFact> BuildFactSet(TicketEntity ticket, DateTimeOffset?activityLocalTimestamp)
        {
            List <AdaptiveFact> factList = new List <AdaptiveFact>();

            if (!string.IsNullOrEmpty(ticket.TicketId))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.TicketIDFact,
                    Value = ticket.TicketId.Substring(0, 8),
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.StatusFactTitle,
                Value = CardHelper.GetUserTicketDisplayStatus(this.ticket),
            });

            if (ticket.Status != (int)TicketState.UnAssigned)
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.ExpertFact,
                    Value = ticket.AssignedToName,
                });
            }

            if (!string.IsNullOrEmpty(ticket.Subject))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.SubjectFact,
                    Value = ticket.Subject,
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.TitleFact,
                Value = CardHelper.TruncateStringIfLonger(this.ticket.Title, CardHelper.TitleMaxDisplayLength),
            });

            if (!string.IsNullOrEmpty(ticket.Description))
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.DescriptionFact,
                    Value = CardHelper.TruncateStringIfLonger(this.ticket.Description, CardHelper.DescriptionMaxDisplayLength),
                });
            }

            factList.Add(new AdaptiveFact
            {
                Title = Strings.DateCreatedDisplayFactTitle,
                Value = CardHelper.GetFormattedDateInUserTimeZone(this.ticket.DateCreated, activityLocalTimestamp),
            });
            if (ticket.Status == (int)TicketState.Pending && this.ticket.PendingComment != null)
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.CommentText,
                    Value = CardHelper.TruncateStringIfLonger(this.ticket.PendingComment, CardHelper.DescriptionMaxDisplayLength),
                });
            }

            if (ticket.Status == (int)TicketState.Resolved)
            {
                factList.Add(new AdaptiveFact
                {
                    Title = Strings.ClosedFactTitle,
                    Value = CardHelper.GetFormattedDateInUserTimeZone(this.ticket.DateClosed.Value, activityLocalTimestamp),
                });
                if (this.ticket.ResolveComment != null)
                {
                    factList.Add(new AdaptiveFact
                    {
                        Title = Strings.CommentText,
                        Value = CardHelper.TruncateStringIfLonger(this.ticket.ResolveComment, CardHelper.DescriptionMaxDisplayLength),
                    });
                }
            }

            return(factList);
        }
Exemple #5
0
        /// <summary>
        /// Returns an attachment based on the state and information of the ticket.
        /// </summary>
        /// <param name="localTimestamp">Local timestamp of the user activity.</param>
        /// <param name="appBaseUri">Application base uri.</param>
        /// <param name="showValidationErrors">Determines whether we show validation errors.</param>
        /// <returns>Returns the attachment that will be sent in a message.</returns>
        public Attachment ToAttachment(DateTimeOffset?localTimestamp, string appBaseUri, bool showValidationErrors)
        {
            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock
                    {
                        Text   = string.Format(CultureInfo.InvariantCulture, Strings.SMETicketHeaderText, this.Ticket.TicketId, this.Ticket.Title),
                        Size   = AdaptiveTextSize.Medium,
                        Weight = AdaptiveTextWeight.Bolder,
                        Wrap   = true,
                    },
                },
            };

            if (this.ticket.KnowledgeBaseQuestion != null)
            {
                card.Body.Add(new AdaptiveTextBlock
                {
                    Text    = string.Format(CultureInfo.InvariantCulture, Strings.SMETicketActualQuestionInKBText, this.Ticket.KnowledgeBaseQuestion),
                    Wrap    = true,
                    Size    = AdaptiveTextSize.Small,
                    Spacing = AdaptiveSpacing.None,
                });
            }
            else
            {
                card.Body.Add(new AdaptiveColumnSet
                {
                    Columns = new List <AdaptiveColumn>
                    {
                        new AdaptiveColumn
                        {
                            Width = "auto",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveImage
                                {
                                    Url = new Uri(string.Format("{0}/content/RedInfoIcon.png", appBaseUri)),
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                    AltText             = "Info icon",
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Width = "auto",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text    = Strings.SMETicketNoQuestionInKBText,
                                    Wrap    = true,
                                    Size    = AdaptiveTextSize.Small,
                                    Spacing = AdaptiveSpacing.None,
                                },
                            },
                        },
                    },
                });
            }

            if (this.Ticket.Status == (int)TicketState.Answered)
            {
                card.Body.Add(new AdaptiveColumnSet
                {
                    Columns = new List <AdaptiveColumn>
                    {
                        new AdaptiveColumn
                        {
                            Width = "80px",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text = Strings.StatusFactTitle,
                                    Wrap = true,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Width   = "auto",
                            Spacing = AdaptiveSpacing.Medium,
                            Items   = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text  = "**" + CardHelper.GetTicketDisplayStatusForSme(this.Ticket, this.updateTicketResponsePayload) + "**",
                                    Color = AdaptiveTextColor.Good,
                                    Wrap  = true,
                                },
                            },
                        },
                    },
                });
            }
            else
            {
                card.Body.Add(new AdaptiveColumnSet
                {
                    Columns = new List <AdaptiveColumn>
                    {
                        new AdaptiveColumn
                        {
                            Width = "80px",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text    = Strings.StatusFactTitle,
                                    Wrap    = true,
                                    Spacing = AdaptiveSpacing.None,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Width   = "auto",
                            Spacing = AdaptiveSpacing.Medium,
                            Items   = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text  = "**" + CardHelper.GetTicketDisplayStatusForSme(this.Ticket, this.updateTicketResponsePayload) + "**",
                                    Color = AdaptiveTextColor.Attention,
                                    Wrap  = true,
                                },
                            },
                        },
                    },
                });
            }

            card.Body.Add(new AdaptiveColumnSet
            {
                Columns = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Width = "80px",
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = Strings.DescriptionFact,
                                Wrap = true,
                            },
                        },
                    },
                    new AdaptiveColumn
                    {
                        Width   = "auto",
                        Spacing = AdaptiveSpacing.Medium,
                        Items   = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text     = this.Ticket.Description,
                                Wrap     = true,
                                MaxLines = 3,
                            },
                        },
                    },
                },
            });

            card.Body.Add(new AdaptiveColumnSet
            {
                Columns = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Width = "80px",
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = Strings.QuestionAskedByFactTitle,
                                Wrap = true,
                            },
                        },
                    },
                    new AdaptiveColumn
                    {
                        Width   = "auto",
                        Spacing = AdaptiveSpacing.Medium,
                        Items   = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = this.Ticket.RequesterName,
                                Wrap = true,
                            },
                        },
                    },
                },
            });

            card.Body.Add(new AdaptiveColumnSet
            {
                Columns = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Width = "80px",
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = Strings.DateFactTitle,
                                Wrap = true,
                            },
                        },
                    },
                    new AdaptiveColumn
                    {
                        Width   = "auto",
                        Spacing = AdaptiveSpacing.Medium,
                        Items   = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = CardHelper.GetFormattedDateInUserTimeZone(this.Ticket.DateCreated, localTimestamp),
                                Wrap = true,
                            },
                        },
                    },
                },
            });

            if (!string.IsNullOrEmpty(this.Ticket.KnowledgeBaseQuestion))
            {
                card.Body.Add(new AdaptiveColumnSet
                {
                    Columns = new List <AdaptiveColumn>
                    {
                        new AdaptiveColumn
                        {
                            Width = "80px",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    Text = Strings.ExistingAnswerFactTitle,
                                    Wrap = true,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Width = "auto",
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveChoiceSetInput
                                {
                                    Id            = Strings.ExistingAnswerFactTitle,
                                    IsMultiSelect = false,
                                    Style         = AdaptiveChoiceInputStyle.Compact,
                                    Value         = Strings.ExistingAnswerFactTitle,
                                    Choices       = new List <AdaptiveChoice>
                                    {
                                        new AdaptiveChoice
                                        {
                                            Title = this.Ticket.KnowledgeBaseAnswer,
                                            Value = Strings.ExistingAnswerFactTitle,
                                        },
                                    },
                                },
                            },
                        },
                    },
                });
            }

            if (this.ticket.AnswerBySME == null && !showValidationErrors)
            {
                card.Actions = this.BuildActions(appBaseUri);
            }
            else
            {
                if (this.updateTicketResponsePayload.Action == UpdateTicketResponsePayload.RespondAction)
                {
                    card.Body.Add(
                        new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = Strings.SMETicketCardYourAnswerLabel,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text  = (showValidationErrors && string.IsNullOrWhiteSpace(this.updateTicketResponsePayload.Answer)) ? Strings.MandatoryAnswerFieldText : string.Empty,
                                        Color = AdaptiveTextColor.Attention,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    });
                    card.Body.Add(new AdaptiveTextInput
                    {
                        Spacing     = AdaptiveSpacing.Small,
                        Id          = nameof(UpdateTicketResponsePayload.AnswerForRespond),
                        Placeholder = Strings.ResponsePlaceholderText,
                        IsMultiline = true,
                        Value       = this.updateTicketResponsePayload.AnswerForRespond,
                    });

                    card.Body.Add(new AdaptiveChoiceSetInput
                    {
                        Id            = nameof(UpdateTicketResponsePayload.AddorAppendAction),
                        IsMultiSelect = true,
                        Style         = AdaptiveChoiceInputStyle.Expanded,
                        Value         = this.updateTicketResponsePayload.AddorAppendAction,
                        Choices       = new List <AdaptiveChoice>
                        {
                            new AdaptiveChoice
                            {
                                Title = Strings.AppendToKBText,
                                Value = Strings.AppendActionMessage,
                            },
                        },
                    });

                    if (showValidationErrors)
                    {
                        card.Actions.Add(new AdaptiveSubmitAction
                        {
                            Title = Strings.SubmitResponseButtonText,
                            Data  = new UpdateTicketResponsePayload
                            {
                                TicketId = this.Ticket.TicketId,
                                Action   = UpdateTicketResponsePayload.RespondAction,
                            },
                        });
                    }
                }
                else if (this.updateTicketResponsePayload.Action == UpdateTicketResponsePayload.AddRespondAction)
                {
                    card.Body.Add(
                        new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = Strings.SMETicketCardYourAnswerLabel,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text  = (showValidationErrors && string.IsNullOrWhiteSpace(this.updateTicketResponsePayload.AnswerForRespond)) ? Strings.MandatoryAnswerFieldText : string.Empty,
                                        Color = AdaptiveTextColor.Attention,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    });
                    card.Body.Add(new AdaptiveTextInput
                    {
                        Spacing     = AdaptiveSpacing.Small,
                        Id          = nameof(UpdateTicketResponsePayload.Answer),
                        Placeholder = Strings.ResponsePlaceholderText,
                        IsMultiline = true,
                        Value       = this.updateTicketResponsePayload.Answer,
                    });

                    card.Body.Add(new AdaptiveChoiceSetInput
                    {
                        Id            = nameof(UpdateTicketResponsePayload.AddorAppendAction),
                        IsMultiSelect = true,
                        Style         = AdaptiveChoiceInputStyle.Expanded,
                        Value         = this.updateTicketResponsePayload.AddorAppendAction,
                        Choices       = new List <AdaptiveChoice>
                        {
                            new AdaptiveChoice
                            {
                                Title = Strings.AddToKBText,
                                Value = Strings.AddActionMessage,
                            },
                        },
                    });

                    if (showValidationErrors)
                    {
                        card.Actions.Add(new AdaptiveSubmitAction
                        {
                            Title = Strings.SubmitResponseButtonText,
                            Data  = new UpdateTicketResponsePayload
                            {
                                TicketId = this.Ticket.TicketId,
                                Action   = UpdateTicketResponsePayload.AddRespondAction,
                            },
                        });
                    }
                }
                else
                {
                    card.Body.Add(new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = Strings.UpdateExistingButtonText,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text  = (showValidationErrors && string.IsNullOrWhiteSpace(this.updateTicketResponsePayload.Answer)) ? Strings.MandatoryAnswerFieldText : string.Empty,
                                        Color = AdaptiveTextColor.Attention,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                        Wrap = true,
                                    },
                                },
                            },
                        },
                    });
                    card.Body.Add(new AdaptiveTextInput
                    {
                        Spacing     = AdaptiveSpacing.Small,
                        Id          = nameof(UpdateTicketResponsePayload.Answer),
                        Placeholder = Strings.ResponsePlaceholderText,
                        IsMultiline = true,
                        Value       = this.updateTicketResponsePayload.Answer,
                    });
                    card.Body.Add(new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "auto",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(string.Format("{0}/content/RedInfoIcon.png", appBaseUri)),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        AltText             = "Info icon",
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Width = "auto",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text    = Strings.WarningMessageOnUpdateAnswer,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Small,
                                        Spacing = AdaptiveSpacing.None,
                                    },
                                },
                            },
                        },
                    });

                    if (showValidationErrors)
                    {
                        card.Actions.Add(new AdaptiveSubmitAction
                        {
                            Title = Strings.SubmitResponseButtonText,
                            Data  = new UpdateTicketResponsePayload
                            {
                                TicketId = this.Ticket.TicketId,
                                Action   = UpdateTicketResponsePayload.UpdateResponseAction,
                            },
                        });
                    }
                }
            }

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = card,
            });
        }