public async Task SendNewCommentEmail(CommentVM comment,int teamId)
        {
            var subscribers = await userRepository.GetSubscribers(teamId, NotificationTypeCode.NewComment);

            var emailTemplate =  emailTemplateRepository.GetEmailTemplate("NewComment");
            if (emailTemplate != null)
            {
                string emailSubject = emailTemplate.Subject;
                string emailBody = emailTemplate.EmailBody;
                Email email = new Email();
               
              
                string issueUrl = UrlBuilderHelper.SiteBaseUrl + "issues/" + comment.IssueId;
                var issueLink = "<a href='" + issueUrl + "'>" + "# " + comment.IssueId + " " + comment.IssueId + "</a>";
                emailBody = emailBody.Replace("@author", comment.Author.Name);
                emailBody = emailBody.Replace("@link", issueLink);
                emailBody = emailBody.Replace("@comment", comment.CommentBody);
                emailBody = emailBody.Replace("@issueId", comment.IssueId.ToString());
                email.Body = emailBody;
                emailSubject = emailSubject.Replace("@issueId", comment.IssueId.ToString());
                email.Subject = emailSubject;

                foreach (var subscriber in subscribers)
                {
                    email.ToAddress.Add(subscriber.EmailAddress);
                }

                email.Send();
            }
        }
Пример #2
0
        public int SaveComment(CommentVM comment)
        {
            comment.Author = new UserDto {Id = this._userSessionHelper.UserId};
            int commentId= this._commentRepository.Save(comment);

          

            return commentId;
        }
 public CommentVM GetCommentVM(int commentId)
 {
     var commentVM = new CommentVM();
     var comment = repo.GetComment(commentId);
     if (comment != null)
     {
         commentVM.ID = comment.ID;
         commentVM.AuthorName = comment.Author.FirstName;
         commentVM.CommentBody = comment.CommentText.ConvertUrlsToLinks();
         commentVM.CreativeDate = comment.CreatedDate;
         commentVM.AvatarHash = UserService.GetAvatarUrl(comment.Author.Avatar, 42);
         commentVM.CreatedDateRelative = comment.CreatedDate.ToShortDateString(); //.ToRelativeDateTime();
     }
     return commentVM;
 }
 public int Save(CommentVM comment)
 {
     using (var db = new TeamEntitiesConn())
     {
         var commentEntity = new Comment();
         commentEntity.IssueID = comment.IssueId;
         commentEntity.CommentText = comment.CommentBody;
         commentEntity.CreatedDate = DateTime.Now;
         commentEntity.CreatedByID = comment.Author.Id;
         ;
         db.Comments.Add(commentEntity);
         db.SaveChanges();
         return commentEntity.ID;
     }
 }
        public async Task<ActionResult> Comment(NewIssueCommentVM model, string Connection)
        {
            try
            {
                if (ModelState.IsValid)
                {

                    model.CommentBody = HttpUtility.HtmlEncode(model.CommentBody);
                    var comment = new CommentVM
                    {
                        CommentBody = model.CommentBody,
                        IssueId = model.IssueID,
                        Author = new UserDto { Id = UserID }
                    };

                    var commentId = commentManager.SaveComment(comment);

                    var newCommentVm = commentManager.GetComment(commentId);
                    var context = GlobalHost.ConnectionManager.GetHubContext<IssuesHub>();

                    //Send to all other users except the Author.
                    newCommentVm.IsOwner = false;
                    string[] excludedConn = new string[] { Connection };
                    context.Clients.Groups(new string[] { TeamID.ToString() }, excludedConn).addNewComment(newCommentVm);

                    //For Sending to the author
                    newCommentVm.IsOwner = true;
                    
                    await commentManager.SendEmailNotificaionForNewComment(comment);

                    return Json(new { Status = "Success", Data = newCommentVm });
                }
                return Json(new { Status = "Error" });
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return Json(new { Status = "Error" });
            }
        }
Пример #6
0
        /// <summary>
        /// Send email to subscribers of the team about the new comment
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public async Task SendEmailNotificaionForNewComment(CommentVM comment)
        {
            try
            {
                var subscibers = await _teamRepository.GetSubscribers(_userSessionHelper.TeamId, "NewComment");
                if (subscibers.Any())
                {
                    var emailTemplate = await _emailRepository.GetEmailTemplate("NewComment");
                    if (emailTemplate != null)
                    {
                        var emailSubject = emailTemplate.Subject;
                        var emailBody = emailTemplate.EmailBody;
                        var email = new Email();


                        foreach (var subsciber in subscibers)
                        {
                            email.ToAddress.Add(subsciber.EmailAddress);
                        }

                        var issueUrl = this._settings.SiteUrl + "/issues/" + comment.IssueId;
                        var issueLink = string.Format("<a href='{0}'>" + "#{1} {2}</a>", issueUrl, comment.IssueId, comment.Issue.Title);

                        emailBody = emailBody.Replace("@author", comment.Author.Name);
                        emailBody = emailBody.Replace("@issueId", comment.IssueId.ToString());
                        emailBody = emailBody.Replace("@link", issueLink);

                        emailBody = emailBody.Replace("@comment", comment.CommentText);
                        emailSubject = emailSubject.Replace("@issueId", comment.IssueId.ToString());

                        email.Body = emailBody;
                        email.Subject = emailSubject;
                        await this._emailManager.Send(email);
                    }
                }
            }
            catch (Exception)
            {
                // Silently fail. We will log this. But we do not want to show an error to user because of this
            }
        }
Пример #7
0
 public CommentVM GetIssueCommentVM(int currentUserId, Comment item)
 {
     var commentVM = new CommentVM { ID = item.ID, CommentBody = item.CommentText, AuthorName = item.Author.FirstName,
         CreativeDate = item.CreatedDate };
     commentVM.CommentBody = commentVM.CommentBody.ConvertUrlsToLinks();
     commentVM.AvatarHash = UserService.GetAvatarUrl(item.Author.Avatar, 42);
     commentVM.CreatedDateRelative = item.CreatedDate.ToJSONFriendlyDateTime();//.ToRelativeDateTime();
     commentVM.IsOwner = item.CreatedByID == currentUserId;
     return commentVM;
 }
 public async Task SendEmailNotificaionForNewComment(CommentVM comment)
 {
     await commentEmailManager.SendNewCommentEmail(comment,userSessionHelper.TeamId);
 }
 public int SaveComment(CommentVM comment)
 {
     return commentRepository.Save(comment);
 }