示例#1
0
        /// <summary>
        /// Saves a Team as a new entry in the DB.
        /// </summary>
        /// <param name="team">Team object to add to the DB.</param>
        /// <returns>ID of the created team on success, 0 on failure.</returns>
        public static int CreateNewTeam(Team team, int contestId)
        {
            try
            {
                int id;

                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    var teamData = new TeamDataProvider
                    {
                        name = team.Name,
                        score = team.Score,
                        contest_id = contestId
                    };
                    data.TeamDataProviders.InsertOnSubmit(teamData);
                    data.SubmitChanges();

                    id = teamData.id;
                }

                UpdateTeamMembers(team);

                return id;
            }
            catch (Exception)
            {
                return 0;
            }
        }
示例#2
0
 /// <summary>
 /// Removes a team from the Contest.
 /// </summary>
 /// <param name="team">The team to be removed.</param>
 public void RemoveTeam(Team team)
 {
     if (team != null)
     {
         this.Teams.Remove(team);
     }
 }
示例#3
0
        /// <summary>
        /// Adds a user to the Contest.
        /// </summary>
        /// <param name="user">User to be added.</param>
        public void AddUser(User user)
        {
            string teamName = String.Format("{0} {1}", user.FirstName, user.LastName);
            //TODO: Assert that no team with this name exists already

            Team newTeam = new Team(teamName);
            newTeam.Add(user);

            this.AddTeam(newTeam);
        }
示例#4
0
 /// <summary>
 /// Adds a team to the Contest.
 /// </summary>
 /// <param name="team">The team to be added.</param>
 public void AddTeam(Team team)
 {
     if (team != null)
     {
         this.Teams.Add(team);
     }
 }
示例#5
0
        /// <summary>
        /// Adds a group to the Contest. In a group contest, members will be added as one team,
        /// while in an individual contest members will be added individually.
        /// </summary>
        /// <param name="group">Group to be added.</param>
        public void AddGroup(Group group)
        {
            if (this.Type == ContestType.Group)
            {
                string teamName = group.Name;
                //TODO: Assert that no team with this name exists already

                Team newTeam = new Team(teamName);

                foreach (User user in group.Members)
                {
                    newTeam.Members.Add(new TeamMember(user));
                }

                this.AddTeam(newTeam);
            }
            else
            {
                foreach (User user in group.Members)
                {
                    this.AddUser(user);
                }
            }
        }
示例#6
0
        /// <summary>
        /// Updates the entry of any members already existing on the team, and creates
        /// new entries for new members of the team.
        /// </summary>
        /// <param name="team">Team whose members must be updated.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool UpdateTeamMembers(Team team)
        {
            try
            {
                foreach (TeamMember user in team.Members)
                {

                    using (SqlConnection connection = ConnectionManager.GetConnection())
                    {
                        var data = new ActivEarthDataProvidersDataContext(connection);

                            TeamMemberDataProvider dbUser =
                                (from u in data.TeamMemberDataProviders
                                 where u.team_id == team.ID && u.user_id == user.User.UserID
                                 select u).FirstOrDefault();
                            if (dbUser != null)
                            {
                                dbUser.initial_score = user.InitialScore;
                                dbUser.initialized = user.Initialized;

                                data.SubmitChanges();
                                return true;
                            }
                            else
                            {
                                if (CreateNewTeamMember(user, team.ID) == 0)
                                {
                                    return false;
                                }
                            }
                    }
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
示例#7
0
        /// <summary>
        /// Updates an existing Team in the DB.
        /// </summary>
        /// <param name="challenge">Team whose record needs updating.</param>
        /// <returns>True on success, false on failure.</returns>
        public static bool UpdateTeam(Team team, int contestId)
        {
            try
            {
                using (SqlConnection connection = ConnectionManager.GetConnection())
                {
                    var data = new ActivEarthDataProvidersDataContext(connection);
                    TeamDataProvider dbTeam =
                        (from c in data.TeamDataProviders where c.id == team.ID select c).FirstOrDefault();
                    if (dbTeam != null)
                    {
                        dbTeam.name = team.Name;
                        dbTeam.score = team.Score;

                        data.SubmitChanges();
                        UpdateTeamMembers(team);
                        return true;
                    }
                    else
                    {
                        CreateNewTeam(team, contestId);
                        return true;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
示例#8
0
        public void TestContestTeamScoreCalculation()
        {
            using (_trans)
            {
                Log("Creating group contest");
                int id = ContestManager.CreateContest(ContestType.Group, "Test Contest 1",
                    "This is a test time-based contest.", 50, DateTime.Now, DateTime.Now.AddDays(1),
                    Statistic.Steps);
                Contest contest = ContestManager.GetContest(id);

                Team team = new Team("Team1");
                team.Add(_group1.Members);
                team.Add(_group2.Members);

                Log("Adding four-member team to contest");
                contest.AddTeam(team);

                Log("Setting individual initial statistics");
                _user1.SetStatistic(Statistic.Steps, 0);
                _user2.SetStatistic(Statistic.Steps, 50);
                _user3.SetStatistic(Statistic.Steps, 100);
                _user4.SetStatistic(Statistic.Steps, 150);

                Log("Locking initial values");
                contest.LockInitialValues();

                Log("Adding 50 steps to each user");
                _user1.SetStatistic(Statistic.Steps, 50);
                _user2.SetStatistic(Statistic.Steps, 100);
                _user3.SetStatistic(Statistic.Steps, 150);
                _user4.SetStatistic(Statistic.Steps, 200);

                Log("Updating contest scores");
                contest.UpdateScores();

                Log("Verifying team aggregate score");
                Assert.AreEqual(200, contest.Teams[0].Score);
            }
        }
示例#9
0
        public void TestGetTeamByTeamId()
        {
            using (_trans)
            {
                Log("Creating contest to put the team in");
                Contest contest = new Contest("Test Contest1", "This is a test contest",
                    30, ContestEndMode.GoalBased, ContestType.Group, DateTime.Today,
                    new EndCondition(500), Statistic.Steps);

                Log("Adding the contest to the DB");
                int contestId = ContestDAO.CreateNewContest(contest);

                Log("Creating team");
                Team team = new Team("Test Team");
                team.Add(new User("Test", "Subject1"));
                team.Add(new User("Test", "Subject2"));

                Log("Adding team to DB");
                int id = TeamDAO.CreateNewTeam(team, contestId);

                Log("Retrieving team from DB");
                Assert.IsNotNull(TeamDAO.GetTeamFromTeamId(id));

            }
        }