public ActionResult NewCode()
        {
            if (!User.IsInRole("Edit"))
            {
                return(View("AuthenticationError"));
            }

            var id           = HttpContext.Request.QueryString["matchId"];
            var confirmation = HttpContext.Request.QueryString["confirmation"] != null;
            var match        = Mongo.Matches.FindOne(Query <Match> .Where(x => x.Id == ObjectId.Parse(id)));

            if (confirmation)
            {
                var allowedSummoners = Mongo.Teams.Find(Query <Team> .Where(team => team.Id == match.BlueTeamId || team.Id == match.RedTeamId))
                                       .SelectMany(team => team.Participants.Select(participant => participant.Summoner.Id))
                                       .ToList();
                TournamentCodeFactory.UpdateTournamentCodePlayers(match.TournamentCode,
                                                                  allowedSummoners);
                TournamentCodeFactory.UpdateTournamentCodePlayersBlind(match.TournamentCodeBlind,
                                                                       allowedSummoners);

                return(RedirectToAction("MatchInfo", "Admin", new RouteValueDictionary {
                    { "matchId", id }
                }));
            }

            return(View(match));
        }
        public ActionResult NewCodeAll()
        {
            if (!User.IsInRole("Edit"))
            {
                return(View("AuthenticationError"));
            }

            var confirmation = HttpContext.Request.QueryString["confirmation"] != null;

            if (confirmation)
            {
                // Update all tournament codes that are currently defined
                foreach (var match in Mongo.Matches.Find(Query <Match> .Where(m => m.TournamentCode != null && m.TournamentCode != "")))
                {
                    try
                    {
                        var allowedSummoners = Mongo.Teams.Find(Query <Team> .Where(team => team.Id == match.BlueTeamId || team.Id == match.RedTeamId))
                                               .SelectMany(team => team.Participants.Select(participant => participant.Summoner.Id))
                                               .ToList();
                        TournamentCodeFactory.UpdateTournamentCodePlayers(match.TournamentCode,
                                                                          allowedSummoners);
                        TournamentCodeFactory.UpdateTournamentCodePlayersBlind(match.TournamentCodeBlind,
                                                                               allowedSummoners);
                    }
                    catch (Exception)
                    {
                    }
                }
                return(RedirectToAction("Index", "Admin"));
            }

            return(View());
        }
        public void Rollback()
        {
            WinnerId        = ObjectId.Empty;
            Finished        = false;
            Invalid         = false;
            InvalidReason   = null;
            SpectateKey     = null;
            PlayedWrongSide = false;

            var allowedSummoners =
                Mongo.Teams.Find(Query <Team> .Where(team => team.Id == BlueTeamId || team.Id == RedTeamId))
                .SelectMany(team => team.Participants.Select(participant => participant.Summoner.Id))
                .ToList();

            TournamentCode      = TournamentCodeFactory.GetTournamentCode(allowedSummoners);
            TournamentCodeBlind = TournamentCodeFactory.GetTournamentCodeBlind(allowedSummoners);
            KillsBlueTeam       = 0;
            KillsRedTeam        = 0;
            AssistsBlueTeam     = 0;
            AssistsRedTeam      = 0;
            DeathsBlueTeam      = 0;
            DeathsRedTeam       = 0;
            ChampionIds         = null;
            BanIds      = null;
            RiotMatchId = 0;

            Mongo.Matches.Save(this);
        }