コード例 #1
0
        public void Load_Tournament(object sender, RoutedEventArgs e)
        {
            //Only load tournament if one is selected
            if (tournamentList.SelectedIndex == -1)
            {
                return;
            }
            var selectedItem         = tournamentList.SelectedItem as TournamentListBoxItem;
            var selectedTournamentId = allTournaments.Where(x => x.TournamentId == selectedItem.TournamentId).First().TournamentId;
            var selectedTournament   = source.getTournament(selectedTournamentId);

            selectedTournament = tournamentController.rebuildTournament(selectedTournament);

            var fullAccess          = user != null;
            TournamentViewUI viewUI = new TournamentViewUI(selectedTournament, fullAccess);

            viewUI.Show();
        }
        private void Create_Tournament_Click(object sender, RoutedEventArgs e)
        {
            var tournamentName  = tournamentNameTextBox.Text;
            var entryFee        = entryFeeTextBox.Text;
            var TournamentType  = (ITournamentType)tournamentTypesComboBox.SelectedItem;
            var prizePool       = totalPrizePool.Text;
            var numParticipants = teamsInTournament.Count;

            var validTournamentName   = tournamentController.validateTournamentName(tournamentName);
            var validEntryFee         = tournamentController.validateEntryFee(entryFee);
            var validTournamentTypeId = tournamentController.validateTournamentType(TournamentType);
            var validParticipantCount = tournamentController.validateParticipantCount(numParticipants, TournamentType);
            var validTotalPrizePool   = tournamentController.validateTotalPrizePool(prizePool, numParticipants, validEntryFee);
            var validatedPrizes       = tournamentController.validatePrizes(prizesInTournament);

            //Add prize structure to create tournament call

            if (!validTournamentName)
            {
                errorMessages.Text = "Please enter a tournament name";
                return;
            }

            if (validEntryFee == -1)
            {
                errorMessages.Text          = "Entry Fee must be an number (ex: 100 or 100.0)";
                entryFeeTextBox.BorderBrush = new SolidColorBrush(Colors.Red);
                return;
            }

            if (!validTournamentTypeId)
            {
                errorMessages.Text = "Please select a Tournament Type";
                return;
            }

            if (!validParticipantCount)
            {
                errorMessages.Text = "Please add a valid amount of teams to the tournament";
                return;
            }

            if (validTotalPrizePool == -1)
            {
                errorMessages.Text = "Prize pool is not valid";
                return;
            }

            if (validatedPrizes == null)
            {
                errorMessages.Text = "Prizes are not valid";
                return;
            }

            errorMessages.Text          = "";
            entryFeeTextBox.BorderBrush = new SolidColorBrush(Colors.DarkGray);

            ITournament newTournament = tournamentController.createTournament(tournamentName,
                                                                              TournamentType,
                                                                              user.UserId,
                                                                              validEntryFee,
                                                                              validTotalPrizePool,
                                                                              teamsInTournament,
                                                                              tournament.Teams,
                                                                              validatedPrizes);

            newTournament.Teams.AddRange(tournament.Teams);

            if (newTournament != null)
            {
                newTournament = source.createTournament(newTournament); //Create Entire Tournament, Set IDs Inside
                TournamentViewUI viewUI = new TournamentViewUI(newTournament);
                viewUI.Show();
                this.Close();
            }
            else //error
            {
                errorMessages.Text = "Must define tournament name and teams in order to continue";
            }
        }