private void NameBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (!ExistingTeams.Contains(TeamNumber))
     {
         if (TeamName.Trim() != "")
         {
             OKBtn.IsEnabled     = true;
             NameBox.BorderBrush = new SolidColorBrush(GRAY_BORDER);
             NameBox.ToolTip     = null;
         }
         else
         {
             OKBtn.IsEnabled     = false;
             NameBox.BorderBrush = new SolidColorBrush(Colors.Red);
             NameBox.ToolTip     = "You must specify a name.";
         }
     }
 }
        public void AddTeamToGameButton(Team team)
        {
            CurrentGame.Teams.Add(team);
            ExistingTeams.Remove(team);

            team.GameID = CurrentGame.InternalID;

            foreach (Player p in team.Players)
            {
                p.GameID = CurrentGame.InternalID;
            }

            Task.Run(() =>
            {
                PlayerHandler.instance.SavePlayers(team.Players.ToArray());
                TeamHandler.instance.SaveTeam(team);
            });
        }
        public async Task DeleteTeamButton(Team TeamToDelete)
        {
            if (TeamToDelete.GameID != CurrentGame.InternalID)
            {
                ////Create warning dialog:
                var messageDialog = new MessageDialog(string.Format(Utils.ResourceLoader.GetString("text_DeleteTeamQuestion_Body"), TeamToDelete.Name), Utils.ResourceLoader.GetString("text_DeleteTeamQuestion_Title"));

                messageDialog.Commands.Add(
                    new UICommand(
                        Utils.ResourceLoader.GetString("text_Delete"),
                        null,
                        0));
                messageDialog.Commands.Add(
                    new UICommand(
                        Utils.ResourceLoader.GetString("text_Cancel"),
                        null,
                        1));

                // Set the command that will be invoked by default
                messageDialog.DefaultCommandIndex = 0;

                // Set the command to be invoked when escape is pressed
                messageDialog.CancelCommandIndex = 1;

                IUICommand Command = await messageDialog.ShowAsync();

                if ((int)Command.Id == 0)
                {
                    TeamHandler.instance.DeleteTeam(TeamToDelete);
                    ExistingTeams.Remove(TeamToDelete);
                }
            }
            else
            {
                CurrentGame.Teams.Remove(TeamToDelete);
                ExistingTeams.Add(TeamToDelete);

                TeamToDelete.GameID = 0;
                TeamHandler.instance.SaveTeam(TeamToDelete);
            }
        }
        public async Task LoadData()
        {
            IsLoading     = true;
            CurrentGame   = GameHandler.instance.GetCurrentGame();
            ExistingTeams = new ObservableCollection <Team>(TeamHandler.instance.GetTeamsFromDatabase());
            ExistingTeams.CollectionChanged     += Teams_CollectionChanged;
            CurrentGame.Teams.CollectionChanged += Teams_CollectionChanged;

            if (ExistingTeams.Count == 0 && CurrentGame.Teams.Count == 0)
            {
                List <Team> NewTeams = new List <Team>();

                for (int i = 0; i < 2; i++)
                {
                    NewTeams.Add(new Team()
                    {
                        Name    = "Team" + (i + 1),
                        Players = new ObservableCollection <Player>(),
                        Points  = 0
                    });
                }

                TeamHandler.instance.SaveTeams(NewTeams);
                ExistingTeams = new ObservableCollection <Team>(NewTeams);
            }

            for (int i = 0; i < ExistingTeams.Count; i++)
            {
                if (CurrentGame.Teams.Where(team => ExistingTeams[i].InternalID == team.InternalID).Count() > 0)
                {
                    ExistingTeams.RemoveAt(i);
                    i--;
                }
            }

            IsLoading = false;
        }
        private void NumberBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            int  n      = -1;
            bool worked = int.TryParse(NumberBox.Text, out n);

            if (!worked)
            {
                NumberBox.Text = TeamNumber.ToString();
            }
            else if (ExistingTeams.Contains(n))
            {
                NumberBox.BorderBrush = new SolidColorBrush(Colors.Red);
                NumberBox.ToolTip     = "A team with that number already exists.";
                OKBtn.IsEnabled       = false;
            }
            else
            {
                TeamNumber = n;

                NumberBox.BorderBrush = new SolidColorBrush(GRAY_BORDER);
                NumberBox.ToolTip     = null;

                if (TeamName.Trim() != "")
                {
                    OKBtn.IsEnabled     = true;
                    NameBox.BorderBrush = new SolidColorBrush(GRAY_BORDER);
                    NameBox.ToolTip     = null;
                }
                else
                {
                    OKBtn.IsEnabled     = false;
                    NameBox.BorderBrush = new SolidColorBrush(Colors.Red);
                    NameBox.ToolTip     = "You must specify a name.";
                }
            }
        }