public async Task SendCommentReplyNotificationAsync(CommentReplyDetail model, string postLink) { if (!IsEnabled) { _logger.LogWarning($"Skipped {nameof(SendCommentReplyNotificationAsync)} because Email sending is disabled."); await Task.CompletedTask; return; } try { var req = new CommentReplyNotificationPayload( model.Email, model.CommentContent, model.Title, model.ReplyContentHtml, postLink); await SendNotificationRequest( new NotificationRequest <CommentReplyNotificationPayload>(MailMesageTypes.AdminReplyNotification, req)); } catch (Exception e) { _logger.LogError(e, e.Message); } }
public Task <Response <CommentReplyDetail> > AddReply(Guid commentId, string replyContent, string ipAddress, string userAgent) { return(TryExecuteAsync <CommentReplyDetail>(async() => { if (!_blogConfig.ContentSettings.EnableComments) { return new FailedResponse <CommentReplyDetail>((int)ResponseFailureCode.CommentDisabled); } var cmt = _commentRepository.Get(commentId); if (null == cmt) { return new FailedResponse <CommentReplyDetail>((int)ResponseFailureCode.CommentNotFound); } var id = Guid.NewGuid(); var model = new CommentReplyEntity { Id = id, ReplyContent = replyContent, IpAddress = ipAddress, UserAgent = userAgent, ReplyTimeUtc = DateTime.UtcNow, CommentId = commentId }; _commentReplyRepository.Add(model); var detail = new CommentReplyDetail { CommentContent = cmt.CommentContent, CommentId = commentId, Email = cmt.Email, Id = model.Id, IpAddress = model.IpAddress, PostId = cmt.PostId, PubDateUtc = cmt.Post.PostPublish.PubDateUtc.GetValueOrDefault(), ReplyContent = model.ReplyContent, ReplyContentHtml = Utils.ConvertMarkdownContent(model.ReplyContent, Utils.MarkdownConvertType.Html), ReplyTimeUtc = model.ReplyTimeUtc, Slug = cmt.Post.Slug, Title = cmt.Post.Title, UserAgent = model.UserAgent }; await _moongladeAudit.AddAuditEntry(EventType.Content, EventId.CommentReplied, $"Replied comment id '{commentId}'"); return new SuccessResponse <CommentReplyDetail>(detail); })); }
public Response <CommentReplyDetail> AddReply(Guid commentId, string replyContent, string ipAddress, string userAgent) { return(TryExecute <CommentReplyDetail>(() => { if (!_blogConfig.ContentSettings.EnableComments) { return new FailedResponse <CommentReplyDetail>((int)ResponseFailureCode.CommentDisabled); } var cmt = _commentRepository.Get(commentId); if (null == cmt) { return new FailedResponse <CommentReplyDetail>((int)ResponseFailureCode.CommentNotFound); } var id = Guid.NewGuid(); var model = new CommentReplyEntity { Id = id, ReplyContent = replyContent, IpAddress = ipAddress, UserAgent = userAgent, ReplyTimeUtc = DateTime.UtcNow, CommentId = commentId }; _commentReplyRepository.Add(model); var detail = new CommentReplyDetail { CommentContent = cmt.CommentContent, CommentId = commentId, Email = cmt.Email, Id = model.Id, IpAddress = model.IpAddress, PostId = cmt.PostId, PubDateUtc = cmt.Post.PostPublish.PubDateUtc.GetValueOrDefault(), ReplyContent = model.ReplyContent, ReplyTimeUtc = model.ReplyTimeUtc, Slug = cmt.Post.Slug, Title = cmt.Post.Title, UserAgent = model.UserAgent }; return new SuccessResponse <CommentReplyDetail>(detail); })); }
public async Task SendCommentReplyNotificationAsync(CommentReplyDetail model, string postLink) { if (string.IsNullOrWhiteSpace(model.Email)) { return; } if (IsEnabled) { _logger.LogInformation("Sending AdminReplyNotification mail"); var pipeline = new TemplatePipeline().Map(nameof(model.ReplyContent), model.ReplyContent) .Map("RouteLink", postLink) .Map("PostTitle", model.Title) .Map(nameof(model.CommentContent), model.CommentContent); await EmailHelper.ApplyTemplate(MailMesageTypes.AdminReplyNotification.ToString(), pipeline) .SendMailAsync(model.Email); } }
public async Task<CommentReplyDetail> AddReply(Guid commentId, string replyContent) { var cmt = await _commentRepository.GetAsync(commentId); if (null == cmt) { throw new InvalidOperationException($"Comment {commentId} is not found."); } var id = Guid.NewGuid(); var model = new CommentReplyEntity { Id = id, ReplyContent = replyContent, ReplyTimeUtc = DateTime.UtcNow, CommentId = commentId }; await _commentReplyRepository.AddAsync(model); var detail = new CommentReplyDetail { CommentContent = cmt.CommentContent, CommentId = commentId, Email = cmt.Email, Id = model.Id, PostId = cmt.PostId, PubDateUtc = cmt.Post.PubDateUtc.GetValueOrDefault(), ReplyContent = model.ReplyContent, ReplyContentHtml = Utils.MarkdownToContent(model.ReplyContent, Utils.MarkdownConvertType.Html), ReplyTimeUtc = model.ReplyTimeUtc, Slug = cmt.Post.Slug, Title = cmt.Post.Title }; await _blogAudit.AddAuditEntry(EventType.Content, AuditEventId.CommentReplied, $"Replied comment id '{commentId}'"); return detail; }