ActivEarth.DAO.ContestDAO.GetActiveContests C# (CSharp) Method

GetActiveContests() public static method

Retrieves all active contests in the DB.
public static GetActiveContests ( bool loadTeams, bool loadTeamMembers ) : List
loadTeams bool
loadTeamMembers bool
return List
        public static List<Contest> GetActiveContests(bool loadTeams, bool loadTeamMembers)
        {
            List<Contest> contests;

            using (SqlConnection connection = ConnectionManager.GetConnection())
            {
                var data = new ActivEarthDataProvidersDataContext(connection);
                contests = (from c in data.ContestDataProviders
                            where c.active
                            select
                                new Contest
                                {
                                    ID = c.id,
                                    Name = c.name,
                                    Description = c.description,
                                    Reward = c.reward,
                                    StartTime = c.start,
                                    EndValue = (float?)c.end_goal,
                                    EndTime = c.end_time,
                                    Mode = (ContestEndMode)c.end_mode,
                                    Type = (ContestType)c.type,
                                    StatisticBinding = (Statistic)c.statistic,
                                    IsActive = c.active,
                                    DeactivatedTime = c.deactivated,
                                    CreatorId = c.creator_id
                                }).ToList();

                if (contests != null)
                {
                    foreach (Contest contest in contests)
                    {
                        if (loadTeams)
                        {
                            contest.Teams = TeamDAO.GetTeamsFromContestId(contest.ID, loadTeamMembers);
                            contest.Teams.Sort(delegate(ContestTeam t1, ContestTeam t2) { return t2.Score.CompareTo(t1.Score); });
                        }

                        contest.FormatString = StatisticInfoDAO.GetStatisticFormatString(contest.StatisticBinding);
                    }
                }

                return contests;
            }
        }