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
            };
 }
 public VoteResponse Downvote(VoteModel voteModel)
 {
     var comment = _session.Get<Comment>(voteModel.CommentId);
     if (comment == null)
     {
         return new VoteResponse
                {
                    Type = CommentResponseType.Error,
                    Message = "Could not find comment to vote"
                };
     }
     Webpage webpage = comment.Webpage;
     User currentUser = CurrentRequestData.CurrentUser;
     if (currentUser != null)
     {
         return RegisterLoggedInVote(voteModel, comment, currentUser, webpage, false);
     }
     return RegisterAnonymousVote(voteModel, comment, webpage, false);
 }
 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
            };
 }