Esempio n. 1
0
        public static Error AddPlayerToTournament(int tournamentID, int userID, int characterID)
        {
            if (IsInTournament(tournamentID, userID))
            {
                return(Error.UserDuplicate);
            }

            MKDBDataContext dc = new MKDBDataContext(con);
            Team            t  = new Team();

            t.Name         = "";
            t.Score        = 0;
            t.TournamentID = tournamentID;
            dc.Teams.InsertOnSubmit(t);
            dc.SubmitChanges();

            TeamMember tm = new TeamMember();

            tm.TeamID      = t.TeamID;
            tm.CharacterID = characterID;
            tm.UserID      = userID;
            dc.TeamMembers.InsertOnSubmit(tm);
            dc.SubmitChanges();
            return(Error.noErrors);
        }
Esempio n. 2
0
        public static Error CloseTournament(int tournamentID)
        {
            MKDBDataContext dc = new MKDBDataContext(con);

            if ((from ma in dc.Matches where ma.Result == 0 && ma.TournamentID == tournamentID select ma).Count() > 0)
            {
                return(Error.Pendingmatches);
            }

            List <TeamInfo> teams    = GetTeams(tournamentID);
            int             maxScore = teams.Max(x => x.Score);

            List <TeamInfo> leadTeams = (from te in teams where te.Score == maxScore select te).ToList();

            if (leadTeams.Count != 1)
            {
                SetRematch(tournamentID, leadTeams.Select(x => x.TeamID).ToList());
                return(Error.Rematch);
            }

            Tournament tournament = (from to in dc.Tournaments where to.TournamentID == tournamentID select to).SingleOrDefault();

            tournament.EndDate     = DateTime.Now;
            tournament.WinerTeamID = leadTeams[0].TeamID;

            dc.SubmitChanges();

            return(Error.noErrors);
        }
Esempio n. 3
0
        public static Error StartTournament(int tournamentID)
        {
            List <TeamInfo> teams = GetTeams(tournamentID);

            if (teams.Count <= 1)
            {
                return(Error.ToLessTeamsInTouranment);
            }
            MKDBDataContext dc = new MKDBDataContext(con);

            for (int i = 0; i < teams.Count - 1; i++)
            {
                for (int j = i + 1; j < teams.Count; j++)
                {
                    Match m = new Match();
                    m.FirstTeamID  = teams[i].TeamID;
                    m.SecondTeamID = teams[j].TeamID;
                    m.TournamentID = tournamentID;
                    m.Result       = 0;
                    dc.Matches.InsertOnSubmit(m);
                }
            }
            Tournament tournament = (from to in dc.Tournaments where to.TournamentID == tournamentID select to).SingleOrDefault();

            tournament.StartDate = DateTime.Now;
            dc.SubmitChanges();

            return(Error.noErrors);
        }
Esempio n. 4
0
        public static Error SetAvatarPath(int userID, string avararPath)
        {
            MKDBDataContext dc   = new MKDBDataContext(con);
            User            user = (from us in dc.Users where us.UserID == userID select us).SingleOrDefault();

            user.AvatarPath = avararPath;
            dc.SubmitChanges();
            return(Error.noErrors);
        }
Esempio n. 5
0
        public static Error AddTeamToTournament(int tournamentID, int userID1, int characterID1, int userID2, int characterID2)
        {
            if (IsInTournament(tournamentID, userID1) || IsInTournament(tournamentID, userID2))
            {
                return(Error.UserDuplicate);
            }

            if (userID1 == userID2)
            {
                return(Error.UserDuplicate);
            }

            if (characterID1 == characterID2)
            {
                return(Error.CharacterDuplicate);
            }

            MKDBDataContext dc = new MKDBDataContext(con);
            Team            t  = new Team();

            t.Name         = "";
            t.Score        = 0;
            t.TournamentID = tournamentID;

            dc.Teams.InsertOnSubmit(t);
            dc.SubmitChanges();

            TeamMember tm1 = new TeamMember();

            tm1.TeamID      = t.TeamID;
            tm1.CharacterID = characterID1;
            tm1.UserID      = userID1;

            TeamMember tm2 = new TeamMember();

            tm2.TeamID      = t.TeamID;
            tm2.CharacterID = characterID2;
            tm2.UserID      = userID2;

            dc.TeamMembers.InsertOnSubmit(tm1);
            dc.TeamMembers.InsertOnSubmit(tm2);
            dc.SubmitChanges();
            return(Error.noErrors);
        }
Esempio n. 6
0
        public static void AddTournament(string name, string type)
        {
            if (name.Length == 0)
            {
                return;
            }
            MKDBDataContext dc = new MKDBDataContext(con);

            Tournament t = new Tournament();

            t.Name             = name;
            t.TournamentTypeID = (from ty in dc.TournamentTypes where ty.Name == type select ty.TournamentTypeID).Single();
            dc.Tournaments.InsertOnSubmit(t);
            dc.SubmitChanges();
        }
Esempio n. 7
0
        public static Error SetMatchResult(int matchID, int result)
        {
            if (result < -2 || result > 2)
            {
                return(Error.WrongResult);
            }
            MKDBDataContext dc = new MKDBDataContext(con);

            Match m = (from ma in dc.Matches where ma.MatchID == matchID select ma).SingleOrDefault();

            m.Result = result;

            dc.SubmitChanges();
            return(Error.noErrors);
        }
Esempio n. 8
0
        public static void OpenTournament(int tournamentID)
        {
            MKDBDataContext dc         = new MKDBDataContext(con);
            Tournament      tournament = (from to in dc.Tournaments where to.TournamentID == tournamentID select to).SingleOrDefault();

            IQueryable <Match> matches = from ma in dc.Matches
                                         where ma.TournamentID == tournamentID
                                         select ma;

            dc.Matches.DeleteAllOnSubmit(matches);

            tournament.StartDate   = null;
            tournament.EndDate     = null;
            tournament.WinerTeamID = null;

            dc.SubmitChanges();
        }
Esempio n. 9
0
        public static int AddUser(string name, string avatarPath)
        {
            if (name.Length == 0)
            {
                return(-1);
            }
            MKDBDataContext dc = new MKDBDataContext(con);

            User user = new User();

            user.Name       = name;
            user.AvatarPath = avatarPath;

            dc.Users.InsertOnSubmit(user);
            dc.SubmitChanges();
            return(user.UserID);
        }
Esempio n. 10
0
        public static Error SetMatchResult(List <IDValuePair> toUpdate)
        {
            MKDBDataContext dc = new MKDBDataContext(con);

            foreach (IDValuePair i in toUpdate)
            {
                if (i.Value < -2 || i.Value > 2)
                {
                    return(Error.WrongResult);
                }

                Match m = (from ma in dc.Matches where ma.MatchID == i.ID select ma).SingleOrDefault();
                m.Result = i.Value;
            }
            dc.SubmitChanges();
            return(Error.noErrors);
        }
Esempio n. 11
0
        public static Error SetRematch(int tournamentID, List <int> TeamIDs)
        {
            MKDBDataContext dc = new MKDBDataContext(con);

            for (int i = 0; i < TeamIDs.Count - 1; i++)
            {
                for (int j = i + 1; j < TeamIDs.Count; j++)
                {
                    Match m = new Match();
                    m.FirstTeamID  = TeamIDs[i];
                    m.SecondTeamID = TeamIDs[j];
                    m.TournamentID = tournamentID;
                    m.Result       = 0;
                    dc.Matches.InsertOnSubmit(m);
                }
            }
            dc.SubmitChanges();
            return(Error.noErrors);
        }