Esempio n. 1
0
        private async void getData(Match m)
        {
            PlayerListVM plvm = PlayerListVM.getInstance();
            var          tlvm = TournamentListVM.getInstance();


            tournament = tlvm.Tournaments.Where(t =>
            {
                return(t.ID == m.TournamentId);
            }).Single();

            team1Player1 = plvm.Players.Where(t =>
            {
                return(t.ID == m.Team1Player1);
            }).Single();

            team1Player2 = plvm.Players.Where(t =>
            {
                return(t.ID == m.Team1Player2);
            }).Single();

            team2Player1 = plvm.Players.Where(t =>
            {
                return(t.ID == m.Team2Player1);
            }).Single();

            team2Player2 = plvm.Players.Where(t =>
            {
                return(t.ID == m.Team2Player2);
            }).Single();
        }
Esempio n. 2
0
        public MatchVM(Match m)
        {
            playerList     = new ObservableCollection <PlayerVM>();
            tournamentList = new ObservableCollection <TournamentVM>();


            foreach (PlayerVM p in PlayerListVM.getInstance().Players)
            {
                playerList.Add(p);
            }
            var tlvm = TournamentListVM.getInstance();

            tournamentList = new ObservableCollection <TournamentVM>(tlvm.
                                                                     Tournaments.Where(tourn => tourn.Timestamp >= DateTime.Today || tourn.ID == m.TournamentId));

            currentMatch = m;
            getData(m);

            ID = m.ID;
            Team1Player1.ID     = m.Team1Player1;
            Team1Player2.ID     = m.Team1Player2;
            Team2Player1.ID     = m.Team2Player1;
            Team2Player2.ID     = m.Team2Player2;
            Finished            = m.Finished;
            Tournament.ID       = m.TournamentId;
            ResultPointsPlayer1 = m.ResultPointsPlayer1;
            ResultPointsPlayer2 = m.ResultPointsPlayer2;
        }
Esempio n. 3
0
 public static PlayerListVM getInstance()
 {
     if (instance == null)
     {
         instance = new PlayerListVM();
     }
     return(instance);
 }
Esempio n. 4
0
        private async void Cancel()
        {
            HttpClient client = new HttpClient();
            string     json   = await client.GetStringAsync(BASE_URL + "api/players/" + currentPlayer.ID);

            client.DefaultRequestHeaders.Add("Authorization", Authentication.token.Token);
            Player player = JsonConvert.DeserializeObject <Player>(json);

            PlayerListVM.getInstance().CurrentPlayer = new PlayerVM(player);
            setProp(player);
            currentPlayer           = player;
            MainWindow.main.Content = new PlayerList();
        }
Esempio n. 5
0
        private async void Create(Player currentPlayer)
        {
            currentPlayer.PhotoPath = currentPlayer.Nickname + ".png";


            isAdmin     = currentPlayer.isAdmin;
            FirstName   = currentPlayer.FirstName;
            LastName    = currentPlayer.LastName;
            Nickname    = currentPlayer.Nickname;
            Skills      = currentPlayer.Skills;
            Password    = currentPlayer.Password;
            PhotoPath   = currentPlayer.PhotoPath;
            isMonday    = currentPlayer.isMonday;
            isTuesday   = currentPlayer.isTuesday;
            isWednesday = currentPlayer.isWednesday;
            isThursday  = currentPlayer.isThursday;
            isFriday    = currentPlayer.isFriday;
            isSaturday  = currentPlayer.isSaturday;



            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("Authorization", Authentication.token.Token);
            string json = JsonConvert.SerializeObject(currentPlayer);

            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(BASE_URL + "api/players/", httpContent);

            if (response.IsSuccessStatusCode)
            {
                string val = await response.Content.ReadAsStringAsync();

                int id;
                int.TryParse(val, out id);

                currentPlayer.ID = id;
                PlayerListVM.getInstance().Players.Add(new PlayerVM(currentPlayer));

                MainWindow.main.Content = new PlayerList();
            }
            else
            {
                ResponseMessage = "Failed to create Player!";
            }
        }
Esempio n. 6
0
        private TournamentListVM()
        {
            pvm             = PlayerListVM.getInstance();
            Tournaments     = new ObservableCollection <TournamentVM>();
            Players         = new ObservableCollection <PlayerVM>();
            originalPlayers = new ObservableCollection <PlayerVM>();

            LoadTournaments();
            chosenPlayers = new ObservableCollection <PlayerVM>();
            Task <ObservableCollection <Player> > task = pvm.LoadPlayer();

            task.ContinueWith(param =>
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    foreach (PlayerVM p in pvm.Players)
                    {
                        Players.Add(p);
                        originalPlayers.Add(p);
                    }
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Players)));
                });
            });
        }