Exemplo n.º 1
0
        public virtual async Task <TblPostComments> PrepareTblCommentsAsync(CommentEditorModel model, string currentUserId, bool published)
        {
            TblPostComments parentComment = null;

            if (model.ReplyToCommentId != null)
            {
                parentComment = await _commentsService.FindByIdAsync(model.ReplyToCommentId.Value);
            }

            var result = new TblPostComments()
            {
                Comment              = model.Comment,
                CommentDate          = DateTime.Now,
                NotifyWhenNewComment = model.NotifyWhenNewComment,
                NotifyWhenReply      = model.NotifyWhenReply,
                PostId          = model.PostId,
                UserEmail       = model.UserEmail,
                UserName        = model.UserName,
                UserId          = currentUserId,
                Published       = published,
                ParentCommentId = parentComment?.Id,
                Quote           = parentComment?.Comment
            };

            return(result);
        }
        public virtual async Task <ActionResult> Update(TblPostComments value)
        {
            var comment = await _commentsService.FindByIdAsync(value.Id);

            comment.Comment     = value.Comment;
            comment.CommentDate = value.CommentDate;
            await _commentsService.UpdateAsync(comment);

            return(Json(value, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public virtual async Task UpdateAsync(TblPostComments record)
        {
            var oldRecord = await FindByIdAsync(record.Id);

            _dbContext.PostComments.AddOrUpdate(record);
            await _dbContext.SaveChangesAsync();

            QueryCacheManager.ExpireTag(CacheTags.Comment);

            _eventPublisher.EntityUpdated(record, oldRecord);
        }
Exemplo n.º 4
0
        public virtual CommentBodyModel PrepareCommentBodyModel(TblPostComments comment, bool isAdmin)
        {
            var parentComment = comment.ParentComment;

            return(new CommentBodyModel()
            {
                Id = comment.Id,
                CommentDate = comment.CommentDate,
                UserName = comment.User != null ? comment.User.FirstName + " " + comment.User.LastName : comment.UserName,
                Comment = comment.Comment,
                Quote = comment.Quote,
                UserAvatar = comment.User != null ? comment.User.Avatar : "",
                PostId = comment.PostId,
                Published = comment.Published,
                CurrentUserIsAdmin = isAdmin,
                ParentCommentUserName = parentComment?.User != null ? parentComment?.User.FirstName + " " + parentComment?.User.LastName : parentComment?.UserName,
                ParentCommentDate = parentComment?.CommentDate ?? DateTime.MinValue,
                ParentCommentId = parentComment?.Id ?? 0
            });
        }
Exemplo n.º 5
0
        public virtual async Task <int> AddAsync(TblPostComments record, bool sendNotifications)
        {
            _dbContext.PostComments.Add(record);
            await _dbContext.SaveChangesAsync();

            QueryCacheManager.ExpireTag(CacheTags.Comment);

            _eventPublisher.EntityInserted(record);

            //Send Notifications
            if (sendNotifications)
            {
                var post = await _postService.FindByIdAsync(record.PostId);

                var urlHelper = new UrlHelper(_httpContext.Request.RequestContext);
                var postUrl   = post.PostType == PostType.Product
                    ? urlHelper.Action("Index", "Product", new { slug = post.Slug }, _httpContext.Request.Url.Scheme)
                    : urlHelper.Action("Post", "Blog", new { slug = post.Slug }, _httpContext.Request.Url.Scheme);

                string userId = "";
                if (record.ParentCommentId != null)
                {
                    userId = await GetUserToNotifyReplyComment(record.ParentCommentId.Value);

                    if (!string.IsNullOrWhiteSpace(userId) && userId != _workContext.CurrentUser?.Id)
                    {
                        await _notificationsService.SendNotificationAsync(userId,
                                                                          "Notification_NewReplySubmittedToYourComment",
                                                                          new
                        {
                            PostTitle = post.Title,
                            Url       = postUrl,
                            Name      = record.UserName,
                            Email     = record.UserEmail
                        });
                    }
                }

                var users = await GetUsersToNotifyNewComment(record.PostId);

                await _notificationsService.SendMultipleNotificationsAsync(
                    users.Where(p => p != _workContext.CurrentUser?.Id && p != userId).ToList(),
                    "Notification_NewCommentSubmitted",
                    new
                {
                    PostTitle = post.Title,
                    Url       = postUrl,
                    Name      = record.UserName,
                    Email     = record.UserEmail
                });

                if (!_workContext.IsAdmin)
                {
                    //Notification to admin
                    await _notificationsService.SendNotificationAsync("Admin",
                                                                      "Notification_NewCommentSubmitted",
                                                                      new
                    {
                        PostTitle = post.Title,
                        Url       = postUrl,
                        Name      = record.UserName,
                        Email     = record.UserEmail
                    });
                }
                //--------------
            }

            return(record.Id);
        }