Exemplo n.º 1
0
        /// <summary>
        /// Adds a user to the tournament of the first bracket.
        /// </summary>
        /// <param name="model">The user model to be added to the tournament</param>
        /// <returns>True if saved; false if save failed</returns>
        private bool AddUserToTournament(TournamentUserModel model)
        {
            // Add the user to the tournament
            services.Tournament.AddTournamentUser(model);

            if (model.PermissionLevel == (int)Permission.TOURNAMENT_STANDARD)
            {
                // Add user to the beginning bracket
                BracketModel bracket  = Model.Brackets.ElementAt(0);
                int?         seedData = bracket.TournamentUsersBrackets.Max(x => x.Seed);
                int          seed     = seedData != null ? seedData.Value + 1 : 1;

                TournamentUsersBracketModel bracketUser = new TournamentUsersBracketModel()
                {
                    TournamentID     = Model.TournamentID,
                    TournamentUserID = model.TournamentUserID,
                    Seed             = seed,
                    BracketID        = bracket.BracketID
                };

                services.Tournament.AddTournamentUsersBracket(bracketUser);
            }

            return(services.Save());
        }
Exemplo n.º 2
0
        private void UpdatePlayers()
        {
            foreach (BracketModel bracketModel in Model.Brackets)
            {
                // Update the Players
                if (bracketModel.TournamentUsersBrackets.Count != Model.TournamentUsers.Where(x => IsUserParticipant(x.TournamentUserID)).Count())
                {
                    for (int j = 0; j < Model.TournamentUsers.Count; j++)
                    {
                        TournamentUserModel         user  = Model.TournamentUsers.ElementAt(j);
                        TournamentUsersBracketModel model = new TournamentUsersBracketModel()
                        {
                            TournamentUserID = user.TournamentUserID,
                            BracketID        = bracketModel.BracketID,
                            TournamentID     = Model.TournamentID,
                            Seed             = j + 1
                        };
                        //bracketModel.TournamentUsersBrackets.Add(model);

                        if (!IsUserAdministrator(user.TournamentUserID))
                        {
                            services.Tournament.AddTournamentUsersBracket(model);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a TournamentUsersBracketModel of this Player.
        /// This Model will also contain the Player's bracketID and seed.
        /// </summary>
        /// <param name="_bracketId">ID of containing Bracket</param>
        /// <param name="_seed">Player's seed-value within the Bracket</param>
        /// <param name="_tournamentId">ID of containing Tournament</param>
        public TournamentUsersBracketModel GetTournamentUsersBracketModel(int _bracketId, int _seed, int _tournamentId)
        {
            TournamentUsersBracketModel model = new TournamentUsersBracketModel();

            //model.TournamentUser = GetTournamentUserModel(_tournamentId);
            model.TournamentUserID = this.Id;
            model.BracketID        = _bracketId;
            model.Seed             = _seed;
            model.TournamentID     = _tournamentId;
            return(model);
        }
Exemplo n.º 4
0
        public void Delete_TournamentUsersBracket()
        {
            var db = new DatabaseRepository("VictoriousEntities");

            TournamentUsersBracketModel t = new TournamentUsersBracketModel()
            {
                TournamentUserID = 1,
                BracketID        = 1,
                Seed             = 1
            };
            var result = db.DeleteTournamentUsersBrackets(t);

            Assert.AreEqual(DbError.SUCCESS, result);
        }
        public void AddTournamentUserBracket_Save()
        {
            TournamentUsersBracketModel t = new TournamentUsersBracketModel()
            {
                TournamentUserID = service.GetAllTournamentUsers()[0].TournamentUserID,
                BracketID        = service.GetAllBrackets()[0].BracketID,
                TournamentID     = service.GetAllTournaments()[0].TournamentID,
                Seed             = 1
            };

            service.AddTournamentUsersBracket(t);
            var result = unitOfWork.Save();

            Assert.AreEqual(true, result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Will progress the tournament and add new players to the net bracket
        /// </summary>
        /// <param name="bracketId">ID of the bracket</param>
        /// <param name="isLocked">Lock or unlock the bracket</param>
        /// <returns>True if saved; false if not saved</returns>
        public bool LockBracket(int bracketId, bool isLocked)
        {
            Tournaments.IBracket currentBracket = Tourny.Brackets.Single(x => x.Id == bracketId);
            Tournaments.IBracket nextBracket    = Tourny.Brackets.ElementAtOrDefault(Tourny.Brackets.FindIndex(x => x == currentBracket) + 1);

            // Make changes to the current bracket
            if (currentBracket != null)
            {
                BracketModel model = Model.Brackets.Single(x => x.BracketID == bracketId);
                model.IsLocked = isLocked;

                services.Tournament.UpdateBracket(model);
            }

            if (nextBracket != null)
            {
                BracketModel nextBracketModel = Model.Brackets.Single(x => x.BracketID == nextBracket.Id);

                List <TournamentUsersBracketModel> usersToProceed = new List <TournamentUsersBracketModel>();
                Tourny.AdvancePlayersByRanking(currentBracket, nextBracket);

                //nextBracketModel.TournamentUsersBrackets = nextBracket.GetModel(Model.TournamentID).TournamentUsersBrackets;

                foreach (Tournaments.IPlayer player in nextBracket.Players)
                {
                    TournamentUsersBracketModel user = new TournamentUsersBracketModel()
                    {
                        BracketID        = nextBracket.Id,
                        TournamentID     = Model.TournamentID,
                        TournamentUserID = player.Id,
                        Seed             = nextBracket.GetPlayerSeed(player.Id)
                    };

                    usersToProceed.Add(user);
                }

                nextBracketModel.TournamentUsersBrackets = usersToProceed;
                services.Tournament.UpdateBracket(nextBracketModel);
            }

            return(services.Save());
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a Model of this Bracket's current state.
        /// Any contained objects (Players, Matches) are also converted into Models.
        /// </summary>
        /// <remarks>
        /// This method is overriden in Group Stages.
        /// </remarks>
        /// <param name="_tournamentID">ID of containing Tournament</param>
        /// <returns>Matching BracketModel</returns>
        public virtual BracketModel GetModel(int _tournamentID)
        {
            BracketModel model = new BracketModel();

            model.TournamentID         = _tournamentID;
            model.BracketID            = this.Id;
            model.BracketTypeID        = Convert.ToInt32(this.BracketType);
            model.Finalized            = this.IsFinalized;
            model.NumberOfGroups       = 0;
            model.MaxRounds            = this.MaxRounds;
            model.NumberPlayersAdvance = this.AdvancingPlayers;

            // Convert the BracketType to relevant model, and add it:
            model.BracketType = new BracketTypeModel();
            model.BracketType.BracketTypeID = model.BracketTypeID;
            model.BracketType.Type          = this.BracketType;
            model.BracketType.TypeName      = this.BracketType.ToString("f");

            // Convert all Players to Models, and add them:
            //model.TournamentUsersBrackets = new List<TournamentUsersBracketModel>();
            foreach (IPlayer player in Players)
            {
                TournamentUsersBracketModel m = player.GetTournamentUsersBracketModel(this.Id, GetPlayerSeed(player.Id), _tournamentID);
                model.TournamentUsersBrackets.Add(m);
            }

            // Convert all Matches to Models, and add them:
            //model.Matches = new List<MatchModel>();
            //if (!(this is IGroupStage))
            //{
            for (int n = 1; n <= NumberOfMatches; ++n)
            {
                model.Matches.Add(GetMatchModel(n));
            }
            //}

            return(model);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Deletes a single TournamentUsersBracket from the database.
        /// </summary>
        /// <param name="tournamentUserId"> The Id of the TournamentUser. </param>
        /// <param name="bracketId"> The Id of the Bracket that the TournamentUser is in. </param>
        public void DeleteTournamentUsersBracket(int tournamentUserId, int bracketId)
        {
            TournamentUsersBracketModel t = GetTournamentUsersBracket(tournamentUserId, bracketId);

            unitOfWork.TournamentUsersBracketRepo.DeleteEntity(t);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Updates a single TournamentUserBracket to the database.
 /// </summary>
 /// <param name="tournamentUserBracket"> The model of the TournamentUsersBracket to update. </param>
 public void UpdateTournamentUsersBracket(TournamentUsersBracketModel tournamentUserBracket)
 {
     unitOfWork.TournamentUsersBracketRepo.Update(tournamentUserBracket);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Adds a single TournamentUsersBracket to the database.
 /// </summary>
 /// <param name="tournamentUserBracket"> The model of the TournamentUsersBracket to be added. </param>
 public void AddTournamentUsersBracket(TournamentUsersBracketModel tournamentUserBracket)
 {
     unitOfWork.TournamentUsersBracketRepo.Add(tournamentUserBracket);
 }
Exemplo n.º 11
0
        public void UpdateSeeds(Dictionary <String, int> players, int bracketId)
        {
            foreach (KeyValuePair <String, int> player in players)
            {
                TournamentUsersBracketModel user = Model.Brackets.Single(x => x.BracketID == bracketId)
                                                   .TournamentUsersBrackets.SingleOrDefault(z => z.TournamentUserID == int.Parse(player.Key));
                if (user != null)
                {
                    user.Seed = player.Value;
                    services.Tournament.UpdateTournamentUsersBracket(user);
                }
                else
                {
                    user = new TournamentUsersBracketModel()
                    {
                        Seed             = player.Value,
                        TournamentUserID = int.Parse(player.Key),
                        TournamentID     = Model.TournamentID,
                        BracketID        = bracketId
                    };

                    services.Tournament.AddTournamentUsersBracket(user);
                }
            }

            // Pass updated seeds to IBracket, which will fix any invalid values:
            Tourny.Brackets.Single(x => x.Id == bracketId)
            .SetNewPlayerlist(Model.Brackets.Single(x => x.BracketID == bracketId)
                              .TournamentUsersBrackets);

            // Give correct values to all user seeds in the first BracketModel.
            // This prevents two users having the same seed and being randomly sorted.
            BracketModel bracketModel = Model.Brackets.First();

            foreach (TournamentUsersBracketModel userModel in bracketModel.TournamentUsersBrackets)
            {
                int newPlayerSeed = Tourny.Brackets
                                    .Single(b => b.Id == bracketModel.BracketID)
                                    .GetPlayerSeed(userModel.TournamentUserID);

                if (newPlayerSeed != userModel.Seed)
                {
                    userModel.Seed = newPlayerSeed;
                    services.Tournament.UpdateTournamentUsersBracket(userModel);
                }
            }
#if false
            foreach (TournamentTeamBracketModel teamModel in bracketModel.TournamentTeamBrackets)
            {
                int newPlayerSeed = Tourny.Brackets
                                    .Single(b => b.Id == bracketModel.BracketID)
                                    .GetPlayerSeed(teamModel.TournamentTeamID);

                if (newPlayerSeed != teamModel.Seed)
                {
                    teamModel.Seed = newPlayerSeed;
                    services.Tournament.UpdateTournamentTeamsBracket(teamModel);
                }
            }
#endif

            services.Save();
        }