/// <summary>
        /// Adds the ticket event notifications for the supplied comment.
        /// </summary>
        /// <param name="comment">The comment for which notifications should be added.</param>
        /// <param name="isGiveUpTicket">if set to <c>true</c> is a give up ticket action.</param>
        /// <param name="subscribers">The subscribers.</param>
        public void AddTicketEventNotifications(TicketComment comment, bool isNewOrGiveUpTicket, string[] subscribers)
        {


            Dictionary<string, string> userReasons = GetNotificationUsersForComment(isNewOrGiveUpTicket, subscribers);
            var newNotes = CreateNotesForUsers(userReasons, comment);
            ScheduleNoteDeliveries(newNotes);

            foreach (var note in newNotes)
            {
                comment.TicketEventNotifications.Add(note);
            }

        }
 /// <summary>
 /// Deprecated Method for adding a new object to the TicketComments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTicketComments(TicketComment ticketComment)
 {
     base.AddObject("TicketComments", ticketComment);
 }
 /// <summary>
 /// Create a new TicketComment object.
 /// </summary>
 /// <param name="ticketId">Initial value of the TicketId property.</param>
 /// <param name="commentId">Initial value of the CommentId property.</param>
 /// <param name="isHtml">Initial value of the IsHtml property.</param>
 /// <param name="commentedBy">Initial value of the CommentedBy property.</param>
 /// <param name="commentedDate">Initial value of the CommentedDate property.</param>
 /// <param name="version">Initial value of the Version property.</param>
 public static TicketComment CreateTicketComment(global::System.Int32 ticketId, global::System.Int32 commentId, global::System.Boolean isHtml, global::System.String commentedBy, global::System.DateTime commentedDate, global::System.Byte[] version)
 {
     TicketComment ticketComment = new TicketComment();
     ticketComment.TicketId = ticketId;
     ticketComment.CommentId = commentId;
     ticketComment.IsHtml = isHtml;
     ticketComment.CommentedBy = commentedBy;
     ticketComment.CommentedDate = commentedDate;
     ticketComment.Version = version;
     return ticketComment;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the activity comment.
        /// </summary>
        /// <param name="activity">The activity.</param>
        /// <param name="commentFlag">The comment flag.</param>
        /// <param name="commentBy">The user making the comment.</param>
        /// <param name="comment">The comment content.</param>
        /// <param name="args">Optional arguments to use as replacement values in the comment text.</param>
        /// <returns></returns>
        private TicketComment GetActivityComment(TicketActivity activity, TicketCommentFlag commentFlag, string comment, string assignedTo, string[] notificationSubscribers, params string[] args)
        {
            TicketComment c = new TicketComment();
            c.Comment = comment;
            c.CommentedBy = Security.CurrentUserName;
            c.CommentedDate = DateTime.Now;
            c.CommentEvent = TicketTextUtility.GetCommentText(activity, commentFlag, args);
            c.IsHtml = false;


            var isNewOrGiveUp = (assignedTo == null) && (activity == TicketActivity.GiveUp || activity == TicketActivity.Create || activity == TicketActivity.CreateOnBehalfOf);
            Notification.AddTicketEventNotifications(c, isNewOrGiveUp, notificationSubscribers);

            return c;
        }
        private List<TicketEventNotification> CreateNotesForUsers(Dictionary<string, string> userReasons, TicketComment comment)
        {
            List<TicketEventNotification> newNotes = new List<TicketEventNotification>();
            var dt = DateTime.Now;
            foreach (var userReason in userReasons)
            {
                var note = new TicketEventNotification();
                note.CreatedDate = dt;
                note.EventGeneratedByUser = comment.CommentedBy;

                //validate email address, if not valid we'll queue the note but not bother sending it (and having to go through the retries)
                bool emailValid = false;
                string email = Security.GetUserEmailAddress(userReason.Key);
                var rxv = new RegexStringValidator(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
                try
                {
                    rxv.Validate(email);
                    emailValid = true;
                }
                catch { }

                note.NotifyEmail = (emailValid && !string.IsNullOrEmpty(email)) ? email : "invalid";
                note.NotifyUser = userReason.Key;
                note.NotifyUserDisplayName = Security.GetUserDisplayName(userReason.Key);
                note.NotifyUserReason = userReason.Value;
                newNotes.Add(note);
            }
            return newNotes;
        }