コード例 #1
0
        public JsonResult Reset(int tournamentId, int bracketId)
        {
            String redirect = Url.Action("Tournament", "Tournament", new { guid = tournamentId });

            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                Models.Bracket    bracket    = tournament.GetBracket(bracketId);

                if (tournament.IsCreator(account.Model.AccountID))
                {
                    bracket.Reset();

                    status  = true;
                    message = "Bracket was reset";
                }
                else
                {
                    status  = false;
                    message = "You do not have permission to do this";
                }
            }
            else
            {
                status   = false;
                message  = "You must login to do this";
                redirect = Url.Action("Login", "Account");
            }

            Session["Message"]       = message;
            Session["Message.Class"] = status ? ViewError.SUCCESS : ViewError.WARNING;
            data = new { redirect = redirect };

            return(BundleJson());
        }
コード例 #2
0
        public JsonResult Reset(int tournamentId, int bracketId, int matchNum)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                Models.Bracket    bracket    = tournament.GetBracket(bracketId);

                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    List <int>    matchNumsAffected = bracket.MatchesAffectedList(matchNum);
                    List <object> matchResponse     = new List <object>();

                    bracket.IBracket.ResetMatchScore(matchNum);

                    foreach (int match in matchNumsAffected)
                    {
                        matchResponse.Add(JsonMatchResponse(bracket.GetMatchByNum(match), true));
                    }

                    status  = true;
                    message = "Matches are reset";
                    data    = new
                    {
                        isLocked = bracket.IsLocked,
                        matches  = matchResponse
                    };
                }
                else
                {
                    message = "You do not have permission to do this";
                }
            }
            else
            {
                message = "You must login to do this";
            }

            return(BundleJson());
        }
コード例 #3
0
        public JsonResult RemoveGame(int tournamentId, int bracketId, int matchNum, int gameNum)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                Models.Bracket    bracket    = tournament.GetBracket(bracketId);

                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    //Models.Match match = bracket.GetMatchByNum(matchNum);
                    List <int>    matchesAffected     = bracket.MatchesAffectedList(matchNum);
                    List <object> matchesAffectedData = new List <object>();

                    if (bracket.RemoveGame(matchNum, gameNum))
                    {
                        foreach (int matchNumber in matchesAffected)
                        {
                            matchesAffectedData.Add(JsonMatchResponse(bracket.GetMatchByNum(matchNumber), true));
                        }

                        status  = true;
                        message = "Matches were updated";
                        data    = new
                        {
                            bracketFinished = bracket.IBracket.IsFinished,
                            isLocked        = bracket.IsLocked,
                            matches         = matchesAffectedData,
                        };
                    }
                    else
                    {
                        message = "There was an error in deleting the game";
                    }
                }
            }

            return(BundleJson());
        }
コード例 #4
0
        public JsonResult Standings(int tournamentId, int bracketId)
        {
            Models.Tournament tournament = new Models.Tournament(service, tournamentId);
            Models.Bracket    bracket    = tournament.GetBracket(bracketId);

            if (bracket == null)
            {
                status  = false;
                message = "Invalid data";
            }
            else
            {
                status  = true;
                message = "Standings Acquired";
                data    = new
                {
                    ranks     = bracket.IBracket.Rankings,
                    usePoints = bracket.UsePoints()
                };
            }

            return(BundleJson());
        }
コード例 #5
0
        public JsonResult MatchInfo(int tournamentId, int bracketId, int matchId)
        {
            Models.Tournament tournament = new Models.Tournament(service, tournamentId);
            Models.Bracket    bracket    = tournament.GetBracket(bracketId);
            Models.Match      match      = bracket.GetMatchById(matchId);

            List <object> matches = new List <object>();

            matches.Add(JsonMatchResponse(match, true));

            if (match != null)
            {
                status  = true;
                message = "Match was loaded.";
                data    = new
                {
                    bracketFinished = bracket.IBracket.IsFinished,
                    isLocked        = bracket.IsLocked,
                    matches         = matches
                };
            }

            return(BundleJson());
        }
コード例 #6
0
        public JsonResult MatchUpdate(int tournamentId, int bracketId, int matchNum, List <GameViewModel> games)
        {
            if (games != null)
            {
                if (account.IsLoggedIn())
                {
                    Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                    Models.Bracket    bracket    = tournament.GetBracket(bracketId);
                    Models.Match      match      = bracket.GetMatchByNum(matchNum);
                    bool validUpdate             = true;

                    if (tournament.IsAdmin(account.Model.AccountID))
                    {
                        // Verify these matches exists
                        foreach (GameViewModel gameModel in games)
                        {
                            PlayerSlot winner       = gameModel.DefenderScore > gameModel.ChallengerScore ? PlayerSlot.Defender : PlayerSlot.Challenger;
                            bool       containsGame = match.match.Games.Any(x => x.GameNumber == gameModel.GameNumber);

                            // Tie game check
                            if (gameModel.ChallengerScore == gameModel.DefenderScore)
                            {
                                continue;
                            }

                            // Add the game
                            if (!match.match.IsFinished && !containsGame)
                            {
                                if (!bracket.AddGame(matchNum, gameModel.DefenderScore, gameModel.ChallengerScore, winner))
                                {
                                    validUpdate = false;
                                    break;
                                }
                            }
                            // Update the game
                            else if (containsGame)
                            {
                                if (!bracket.UpdateGame(matchNum, gameModel.GameNumber, gameModel.DefenderScore, gameModel.ChallengerScore, winner))
                                {
                                    validUpdate = false;
                                    break;
                                }
                            }
                        }

                        // Updating of the matches happens by an event.
                        status = bracket.UpdateMatch(bracket.IBracket.GetMatchModel(matchNum));
                        match  = bracket.GetMatchByNum(matchNum);
                        bool refresh = bracket.roundsModified;

                        List <int>    matchesAffected = bracket.MatchesAffectedList(matchNum);
                        List <object> matchUpdates    = new List <object>();

                        if (status)
                        {
                            message = "Current match was updated";

                            // Creates objects for all matches affected, including the match you're currently on
                            foreach (int matchNumAffected in matchesAffected)
                            {
                                matchUpdates.Add(JsonMatchResponse(bracket.GetMatchByNum(matchNumAffected), false));
                            }
                        }

                        // Prepare data
                        data = new
                        {
                            bracketFinished = bracket.IBracket.IsFinished,
                            isLocked        = bracket.IsLocked,
                            matches         = matchUpdates,
                            refresh         = refresh
                        };
                    }
                    else
                    {
                        message = "You are not authorized to do this.";
                    }
                }
                else
                {
                    message = "You must login to do this action.";
                }
            }
            else
            {
                message = "No games were received.";
            }

            return(BundleJson());
        }