Пример #1
0
 private VoteResponse RegisterAnonymousVote(VoteModel voteModel, Comment comment, Webpage webpage, bool isUpvote)
 {
     if (comment.Votes.Any(v => v.IPAddress == voteModel.IPAddress))
     {
         return new VoteResponse
                {
                    Type = CommentResponseType.Info,
                    Message = "Already voted",
                    RedirectUrl = "~/" + webpage.LiveUrlSegment
                };
     }
     var vote = new Vote
                {
                    IsUpvote = isUpvote,
                    Comment = comment,
                    IPAddress = voteModel.IPAddress
                };
     comment.Votes.Add(vote);
     _session.Transact(session => session.Save(vote));
     return new VoteResponse
            {
                Message = "Vote registered",
                RedirectUrl = "~/" + webpage.LiveUrlSegment,
                Type = CommentResponseType.Success
            };
 }
Пример #2
0
 public CommentsViewInfo GetReplyToInfo(Comment comment)
 {
     Webpage webpage = comment.Webpage;
     if (webpage == null || !webpage.AreCommentsEnabled(_getWebpageCommentingInfo.Get(webpage), _settings))
     {
         return new CommentsViewInfo { Disabled = true };
     }
     if (!_settings.AllowGuestComments && CurrentRequestData.CurrentUser == null)
     {
         return new CommentsViewInfo { Disabled = true };
     }
     if (CurrentRequestData.CurrentUser == null)
     {
         return new CommentsViewInfo
                {
                    View = "GuestReply",
                    Model = new GuestAddCommentModel { WebpageId = webpage.Id, InReplyTo = comment.Id },
                };
     }
     return new CommentsViewInfo
            {
                View = "LoggedInReply",
                Model = new LoggedInUserAddCommentModel { WebpageId = webpage.Id, InReplyTo = comment.Id },
            };
 }
Пример #3
0
        public void Send(Comment comment)
        {
            if (Convert.ToBoolean(comment.Approved))
            {
                // Comment needs to be a 'reply' to another comment.
                if (comment.InReplyTo != null)
                {
                    // Parent Comment needs to have notifications enabled.
                    if (comment.InReplyTo.SendReplyNotifications)
                    {
                        // Notifcation must not have already been sent.
                        if (!comment.ParentNotificationSent)
                        {
                            // Send
                            var queuedMessage = _messageParser.GetMessage(comment);
                            if (queuedMessage != null)
                            {
                                _messageParser.QueueMessage(queuedMessage);

                                comment.ParentNotificationSent = true;
                                _session.Transact(session => session.Update(comment));
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
 private PostCommentResponse GetResponse(Comment comment)
 {
     bool pending = comment.Approved != true;
     return new PostCommentResponse
            {
                Valid = true,
                Pending = pending,
                Message = pending
                    ? _stringResourceProvider.GetValue(PendingApprovalMessage)
                    : _stringResourceProvider.GetValue(AddedMessage),
                RedirectUrl = "~/" + comment.Webpage.LiveUrlSegment
            };
 }
Пример #5
0
 private static void AddNewCommentToReplyChildren(Comment comment)
 {
     if (comment.InReplyTo != null)
     {
         comment.InReplyTo.Children.Add(comment);
     }
 }
Пример #6
0
 public PostCommentResponse AddLoggedInComment(LoggedInUserAddCommentModel model)
 {
     User currentUser = CurrentRequestData.CurrentUser;
     if (IsValid(model) && currentUser != null)
     {
         var comment = new Comment
                       {
                           User = currentUser,
                           Name = currentUser.GetCommentsInfo().Username,
                           Email = currentUser.Email,
                           Message = model.Message,
                           Webpage = GetWebpage(model),
                           Approved = _settings.CommentApprovalType == CommentApprovalType.All ? (bool?)null : true,
                           InReplyTo = GetInReplyTo(model),
                           IPAddress = model.IPAddress,
                           SendReplyNotifications = model.ReplyNotification
                       };
         AddNewCommentToReplyChildren(comment);
         _session.Transact(session => session.Save(comment));
         return GetResponse(comment);
     }
     return new PostCommentResponse { Valid = false };
 }
Пример #7
0
 public PostCommentResponse AddGuestComment(GuestAddCommentModel model)
 {
     if (_settings.AllowGuestComments)
     {
         var comment = new Comment
                       {
                           Email = model.Email,
                           Name = model.Name,
                           Message = model.Message,
                           Webpage = GetWebpage(model),
                           Approved =
                               _settings.CommentApprovalType == CommentApprovalType.None
                                   ? true
                                   : (bool?)null,
                           InReplyTo = GetInReplyTo(model),
                           IPAddress = model.IPAddress,
                           SendReplyNotifications = model.ReplyNotification
                       };
         AddNewCommentToReplyChildren(comment);
         _session.Transact(session => session.Save(comment));
         return GetResponse(comment);
     }
     return new PostCommentResponse { Valid = false };
 }
Пример #8
0
 public ActionResult ShowComment(Comment comment, int depth = 1)
 {
     ViewData["depth"] = depth;
     return PartialView(comment);
 }
Пример #9
0
 public ActionResult ReplyTo(Comment comment)
 {
     CommentsViewInfo info = _commentsUiService.GetReplyToInfo(comment);
     return ReturnView(info);
 }
Пример #10
0
 public ActionResult Votes(Comment comment)
 {
     return PartialView(comment);
 }
Пример #11
0
 private VoteResponse RegisterLoggedInVote(VoteModel voteModel, Comment comment, User currentUser,
     Webpage webpage, bool isUpvote)
 {
     if (comment.Votes.Any(v => v.IsUpvote == isUpvote && v.User == currentUser))
     {
         return new VoteResponse
                {
                    Type = CommentResponseType.Info,
                    Message = "Already voted",
                    RedirectUrl = "~/" + webpage.LiveUrlSegment
                };
     }
     List<Vote> oppositeVotes =
         comment.Votes.Where(v => v.IsUpvote != isUpvote && v.User == currentUser).ToList();
     _session.Transact(session => oppositeVotes.ForEach(v =>
                                                        {
                                                            comment.Votes.Remove(v);
                                                            session.Delete(v);
                                                        }));
     var vote = new Vote
                {
                    IsUpvote = isUpvote,
                    User = currentUser,
                    Comment = comment,
                    IPAddress = voteModel.IPAddress
                };
     comment.Votes.Add(vote);
     _session.Transact(session => session.Save(vote));
     return new VoteResponse
            {
                Message = "Vote registered",
                RedirectUrl = "~/" + webpage.LiveUrlSegment,
                Type = CommentResponseType.Success
            };
 }
 public void Unsubscribe(Comment comment)
 {
     comment.SendReplyNotifications = false;
     _session.Transact(session => session.Update(comment));
 }
Пример #13
0
 public void Delete(Comment comment)
 {
     _session.Transact(session => session.Delete(comment));
 }
Пример #14
0
 public void Update(Comment comment)
 {
     _session.Transact(session => session.Update(comment));
 }
Пример #15
0
 public CommentReportedEventArgs(Comment comment)
 {
     Comment = comment;
 }