Wrapper class for Users for use with Contests. Allows for the calculation of score contributions since the beginning of a contest.
Esempio n. 1
0
        /// <summary>
        /// Creates a new DB entry for a team member.
        /// </summary>
        /// <param name="teamMember">Member to be added to the DB.</param>
        /// <param name="teamId">Team ID that the member should be added to.</param>
        /// <returns>ID of the newly added Team Member entry on success, 0 on failure.</returns>
        public static int CreateNewTeamMember(ContestTeamMember teamMember, int teamId)
        {
            try
            {
                int contestId = TeamDAO.GetContestIdFromTeamId(teamId);

                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    if (TeamDAO.UserCompetingInContest(teamMember.UserId, contestId)) { throw new Exception("User is already competing in the contest"); }

                    var data = new ActivEarthDataProvidersDataContext(connection);
                    var userData = new TeamMemberDataProvider
                    {
                        contest_id = contestId,
                        team_id = teamId,
                        user_id = teamMember.UserId,
                        score = teamMember.Score,
                        initialized = teamMember.Initialized,
                        initial_score = teamMember.InitialScore
                    };
                    data.TeamMemberDataProviders.InsertOnSubmit(userData);
                    data.SubmitChanges();
                    return userData.id;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new DB entry for a team member.
        /// </summary>
        /// <param name="userId">ID of the Member to be added to the DB.</param>
        /// <param name="teamId">Team ID that the member should be added to.</param>
        /// <returns>ID of the newly added Team Member entry on success, 0 on failure.</returns>
        public static int CreateNewTeamMember(int userId, int teamId)
        {
            try
            {
                ContestTeamMember member = new ContestTeamMember()
                {
                    UserId = userId
                };

                return TeamDAO.CreateNewTeamMember(member, teamId);
            }
            catch (Exception)
            {
                return 0;
            }
        }