ActivEarth.DAO.ContestDAO.GetContestFromContestId C# (CSharp) Метод

GetContestFromContestId() публичный статический Метод

Retrieves a Contest from the DB based on its ID.
public static GetContestFromContestId ( int contestId, bool loadTeams, bool loadTeamMembers ) : Contest
contestId int Identifier of the contest to retrieve.
loadTeams bool
loadTeamMembers bool
Результат ActivEarth.Objects.Competition.Contests.Contest
        public static Contest GetContestFromContestId(int contestId, bool loadTeams, bool loadTeamMembers)
        {
            Contest contest;
            using (SqlConnection connection = ConnectionManager.GetConnection())
            {
                var data = new ActivEarthDataProvidersDataContext(connection);
                contest = (from c in data.ContestDataProviders
                           where c.id == contestId
                           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,
                                   IsSearchable = c.searchable,
                                   DeactivatedTime = c.deactivated,
                                   CreatorId = c.creator_id
                               }).FirstOrDefault();
            }

            if (contest != null)
            {
                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 contest;
        }