示例#1
0
    public static List <ContestParticipant> GetForumParticipants(Contest contest)
    {
        try
        {
            var users        = TableHelper.GetListFromQuery <Member>(@"WHERE Users.AccountStatusInt = 9 
                                                                    OR Users.AccountStatusInt = 1 
                                                                    OR Users.AccountStatusInt = 10");
            var participants = new List <string>();

            foreach (Member user in users)
            {
                if (contest.CanMemberParticipate(user, true))
                {
                    participants.Add(user.Name);
                }
            }

            DataTable result;
            using (var bridge = ParserPool.Acquire(Database.Forum))
            {
                result = bridge.Instance.ExecuteRawCommandToDataTable(@"select COUNT(m.MessageID), us.Name from yaf_Message m 
                                                                            INNER JOIN yaf_Topic t ON t.TopicID = m.TopicID 
                                                                            INNER JOIN yaf_User us ON us.UserID = m.UserID
                                                                            INNER JOIN yaf_Forum f ON f.ForumID = t.ForumID 
                                                                            WHERE m.IsDeleted = 0 
                                                                            AND m.IsApproved = 1 
                                                                            AND m.Posted > '" + contest.DateStart.ToDBString() +
                                                                      "' AND m.Posted < '" + contest.DateEnd.ToDBString() +
                                                                      "' AND f.ForumID in (select ForumId from ForumContests where ContestId = " + contest.Id + @") 
                                                                            GROUP BY us.Name;");
            }

            List <ContestParticipant> list = new List <ContestParticipant>(result.Rows.Count);

            foreach (DataRow row in result.Rows)
            {
                ContestParticipant participant = new ContestParticipant();
                participant.Username = (string)row[1];

                if (participants.Contains(participant.Username))
                {
                    participant.Points       = new Money(Convert.ToDecimal(row[0]));
                    participant.LatestAction = DateTime.Now.Zero();
                    participant.ContestId    = contest.Id;

                    list.Add(participant);
                }
            }



            return(list);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }