Exemplo n.º 1
0
        public CountVote CalculateVoteCount(int postID)
        {
            CountVote    coutnvote = null;
            const string sql       = "SELECT SUM(CASE WHEN IsUp=1 THEN 1 ELSE 0 END) UpVotes, SUM(CASE WHEN IsUp=0 THEN 1 ELSE 0 END) DownVotes FROM pf_PostVote WHERE PostID = @PostID GROUP BY PostID";
            var          count     = 0;

            _sqlObjectFactory.GetConnection().Using(c => c.Command(sql)
                                                    .AddParameter("@PostID", postID)
                                                    .ExecuteReader()
                                                    .ReadOne(r => coutnvote = new CountVote {
                Votes = r.GetInt32(0), DownVotes = r.GetInt32(1)
            }));
            return(coutnvote);
        }
Exemplo n.º 2
0
        public CountVote GetVoteCount(int postID)
        {
            CountVote    coutnvote = null;
            const string sql       = "SELECT Votes,DownVotes FROM pf_Post WHERE PostID = @PostID";
            var          votes     = 0;

            _sqlObjectFactory.GetConnection().Using(c => c.Command(sql)
                                                    .AddParameter("@PostID", postID)
                                                    .ExecuteReader()
                                                    .ReadOne(r => coutnvote = new CountVote {
                Votes = r.GetInt32(0), DownVotes = r.GetInt32(1)
            }));
            return(coutnvote);
        }