Ejemplo n.º 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
            };
 }
Ejemplo n.º 2
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
            };
 }