Example #1
0
        public async Task <HttpStatusCode> Post()
        {
            bool       success    = true;
            HttpClient httpClient = new HttpClient();
            Uri        uri        = new Uri(DataSource.host + "goal" + "?access_token=" + DataSource.accessToken);
            List <KeyValuePair <string, string> > pairsToSend = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("match_id", this.match_id.ToString()),
                new KeyValuePair <string, string>("team_id", this.team_id.ToString()),
                new KeyValuePair <string, string>("player_id", this.player_id.ToString()),
                new KeyValuePair <string, string>("assistant_id", this.assistant_id.ToString()),
                new KeyValuePair <string, string>("is_penalty", this.is_penalty.ToString().ToLower()),
                new KeyValuePair <string, string>("is_autogoal", this.is_autogoal.ToString().ToLower()),
                new KeyValuePair <string, string>("minute", this.minute.ToString()),
                new KeyValuePair <string, string>("addition_minute", this.addition_minute.ToString()),
            };
            var content  = new FormUrlEncodedContent(pairsToSend);
            var response = await httpClient.PostAsync(uri, content);

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                objectStatus = (int)DataSource.status.needCreate;
                success      = false;
            }
            if (!success)
            {
                FootballMatch fm = await DataSource.GetItemAsync(this.match_id);

                objectStatus = (int)DataSource.status.needCreate;
                fm.goals.Add(this);
                throw new Exception("EnsureSuccessStatusCodeFailed");
            }
            string result = await response.Content.ReadAsStringAsync();

            JsonObject jsonObject = JsonObject.Parse(result);

            if (jsonObject.Count == 0)
            {
            }
            else
            {
                await DataSource.RefreshGoalsCollectionAsync(Match_idValue);
            }
            objectStatus = (int)DataSource.status.ok;
            return(response.StatusCode);
        }
        public async Task <bool> Post()
        {
            bool       success    = true;
            HttpClient httpClient = new HttpClient();
            Uri        uri        = new Uri(DataSource.host + "match_player" + "?access_token=" + DataSource.accessToken);
            List <KeyValuePair <string, string> > pairsToSend = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("match_id", this.match_id.ToString()),
                new KeyValuePair <string, string>("team_id", this.team_id.ToString()),
                new KeyValuePair <string, string>("player_id", this.player_id.ToString()),
                new KeyValuePair <string, string>("teamsheet", this.teamsheet.ToString()),
                new KeyValuePair <string, string>("is_capitan", this.is_capitan.ToString().ToLower()),
                new KeyValuePair <string, string>("is_goalkeeper", this.is_goalkeeper.ToString().ToLower()),
            };
            var content  = new FormUrlEncodedContent(pairsToSend);
            var response = await httpClient.PostAsync(uri, content);

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                success = false;
            }
            if (!success)
            {
                FootballMatch fm = await DataSource.GetItemAsync(this.match_id);

                objectStatus = (int)DataSource.status.needCreate;
                fm.matchPlayers.Add(this);
                throw new Exception(response.StatusCode.ToString());
                return(false);
            }
            string result = await response.Content.ReadAsStringAsync();

            JsonObject jsonObject = JsonObject.Parse(result);

            if (jsonObject.Count == 0)
            {
                return(false);
            }
            else
            {
                await Get();
            }
            objectStatus = (int)DataSource.status.ok;
            return(true);
        }
        public async Task <HttpStatusCode> Post()
        {
            bool       success    = true;
            HttpClient httpClient = new HttpClient();
            Uri        uri        = new Uri(DataSource.host + "red_card" + "?access_token=" + DataSource.accessToken);
            List <KeyValuePair <string, string> > pairsToSend = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("match_id", this.match_id.ToString()),
                new KeyValuePair <string, string>("team_id", this.team_id.ToString()),
                new KeyValuePair <string, string>("player_id", this.player_id.ToString()),
                new KeyValuePair <string, string>("is_two_yellow", this.is_two_yellow.ToString().ToLower()),
                new KeyValuePair <string, string>("minute", this.minute.ToString()),
                new KeyValuePair <string, string>("addition_minute", this.addition_minute.ToString()),
                new KeyValuePair <string, string>("note", this.note),
            };
            var content  = new FormUrlEncodedContent(pairsToSend);
            var response = await httpClient.PostAsync(uri, content);

            try
            {
                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                success = false;
            }
            if (!success)
            {
                FootballMatch fm = await DataSource.GetItemAsync(this.match_id);

                objectStatus = (int)DataSource.status.needCreate;
                fm.redcards.Add(this);
            }
            string result = await response.Content.ReadAsStringAsync();

            JsonObject jsonObject = JsonObject.Parse(result);

            objectStatus = (int)DataSource.status.ok;
            await DataSource.RefreshRedCardsCollectionAsync(Match_idValue);

            return(response.StatusCode);
        }
 public DataGroupRCPlayers(FootballMatch match, FootballTeam team, Player player, RedCard redCard)
 {
     this.match = match;
     this.team = team;
     this.player = player;
     this.redCard = redCard;
 }
        public DataGroupMatchPlayers(FootballMatch match, FootballTeam team, Player player)
        {
            this.match = match;
            this.team = team;
            this.player = player;
            this.matchPlayer = new MatchPlayer(-1, -1, -1, -1);
            this.showProperties = false;

        }
 public DataGroupGoalsPlayers(FootballMatch match, FootballTeam team, Player player, Goal goal)
 {
     this.match = match;
     this.team = team;
     this.player = player;
     this._goals = goal;
 }
 public ConcTime(string DateTime, FootballMatch fm)
 {
     this.fm = fm;
     time = DateTime.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Distinct().Last();
 }
        private async Task GetRefereeMatchCollectionAsync()
        {
            if (this._tournaments.Count != 0)
            {
                return;
            }
            if (DataSource.busy == true)
            {
                return;
            }
            try
            {
                busy = true;
                Uri dataUri = new Uri(host + "referee/me/match?access_token=" + accessToken + "&filter=future");
                var responseR = await httpClient.GetAsync(dataUri);
                try
                {
                    responseR.EnsureSuccessStatusCode();
                }
                catch (Exception ex)
                {
                    if (responseR.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        logout();
                    }
                    //
                    //Возможно, следует обрабатывать исключение здесь и возвращать HttpStatusCode здесь и во всех подобных запросах, которые сейчас кидают Exception
                    //
                    throw new Exception(ex.Message);
                    return;
                }
                JsonArray jsonArray;
                string resultR = await responseR.Content.ReadAsStringAsync();
                JsonObject jsonObject = JsonObject.Parse(resultR);
                if (jsonObject.ContainsKey("rows"))
                {
                    jsonArray = jsonObject["rows"].GetArray();
                    if (jsonArray.Count > 0)
                    {
                        foreach (JsonValue itemValue in jsonArray)
                        {
                            JsonObject itemObject = itemValue.GetObject();
                            //JsonObject groupObject = jsonArray[0].GetObject();
                            FootballMatch item = new FootballMatch((int)itemObject["id"].GetNumber(), true);
                            if (itemObject["start_at"].ValueType.Equals(JsonValueType.String)) item.start_at = itemObject["start_at"].GetString();
                            if (itemObject["place"].ValueType.Equals(JsonValueType.String)) item.place = itemObject["place"].GetString();
                            if (itemObject["goals1"].ValueType.Equals(JsonValueType.Number)) item.goals1 = (int)itemObject["goals1"].GetNumber();
                            if (itemObject["goals2"].ValueType.Equals(JsonValueType.Number)) item.goals2 = (int)itemObject["goals2"].GetNumber();
                            if (itemObject["penalty1"].ValueType.Equals(JsonValueType.Number)) item.penalty1 = (int)itemObject["penalty1"].GetNumber();
                            if (itemObject["penalty2"].ValueType.Equals(JsonValueType.Number)) item.penalty2 = (int)itemObject["penalty2"].GetNumber();
                            if (itemObject["round_id"].ValueType.Equals(JsonValueType.Number)) item.round_id = (int)itemObject["round_id"].GetNumber();
                            if (itemObject["is_technical"].ValueType.Equals(JsonValueType.Boolean)) item.is_technical = (bool)itemObject["is_technical"].GetBoolean();
                            if (itemObject["is_overtime"].ValueType.Equals(JsonValueType.Boolean)) item.is_overtime = (bool)itemObject["is_overtime"].GetBoolean();
                            if (itemObject["is_shootout"].ValueType.Equals(JsonValueType.Boolean)) item.is_shootout = (bool)itemObject["is_shootout"].GetBoolean();
                            JsonObject jsonObjectTeam = itemObject["team1"].GetObject();
                            FootballTeam _team1 = new FootballTeam((int)(jsonObjectTeam["id"].GetNumber()));
                            _team1.title = jsonObjectTeam["title"].GetString();
                            if (jsonObjectTeam["image_path"].ValueType.Equals(JsonValueType.String)) _team1.image_path = jsonObjectTeam["image_path"].GetString();
                            else _team1.image_path = "ms-appx:///Assets/noIm.png";
                            item.team1 = _team1;
                            jsonObjectTeam = itemObject["team2"].GetObject();
                            FootballTeam _team2 = new FootballTeam((int)(jsonObjectTeam["id"].GetNumber()));
                            _team2.title = jsonObjectTeam["title"].GetString();
                            if (jsonObjectTeam["image_path"].ValueType.Equals(JsonValueType.String)) _team2.image_path = jsonObjectTeam["image_path"].GetString();
                            else _team2.image_path = "ms-appx:///Assets/noIm.png";
                            item.team2 = _team2;
                            Addition ad = new Addition(0);
                            bool b = await ad.Get(item.id);
                            if (b)
                            {
                                item.addition = ad;
                            }
                            b = false;

                            try { await GetItemsForMatch(item); }
                            catch (Exception ex)
                            {
                                busy = false;
                                throw new Exception("Error aquired while loading data " + ex.Message);
                            }
                        }
                    }
                }
                //this.Groups.Add(actual);

                dataUri = new Uri(host + "referee/me/match?access_token=" + accessToken + "&filter=past");
                var responseL = await httpClient.GetAsync(dataUri);
                try
                {
                    responseL.EnsureSuccessStatusCode();
                }
                catch (Exception ex)
                {
                    busy = false;
                    return;
                }
                string resultL = await responseL.Content.ReadAsStringAsync();
                JsonObject jsonObjectL = JsonObject.Parse(resultL);
                if (jsonObjectL.ContainsKey("rows"))
                {
                    jsonArray = jsonObjectL["rows"].GetArray();
                    if (jsonArray.Count > 0)
                    {
                        //DataGroup past = new DataGroup(false);
                        foreach (JsonValue itemValue in jsonArray)
                        {
                            JsonObject itemObject = itemValue.GetObject();
                            FootballMatch item = new FootballMatch(((int)itemObject["id"].GetNumber()), false);
                            if (itemObject["start_at"].ValueType.Equals(JsonValueType.String)) item.start_at = itemObject["start_at"].GetString();
                            if (itemObject["place"].ValueType.Equals(JsonValueType.String)) item.place = itemObject["place"].GetString();
                            if (itemObject["goals1"].ValueType.Equals(JsonValueType.Number)) item.goals1 = (int)itemObject["goals1"].GetNumber();
                            if (itemObject["goals2"].ValueType.Equals(JsonValueType.Number)) item.goals2 = (int)itemObject["goals2"].GetNumber();
                            if (itemObject["penalty1"].ValueType.Equals(JsonValueType.Number)) item.penalty1 = (int)itemObject["penalty1"].GetNumber();
                            if (itemObject["penalty2"].ValueType.Equals(JsonValueType.Number)) item.penalty2 = (int)itemObject["penalty2"].GetNumber();
                            if (itemObject["round_id"].ValueType.Equals(JsonValueType.Number)) item.round_id = (int)itemObject["round_id"].GetNumber();
                            if (itemObject["is_technical"].ValueType.Equals(JsonValueType.Boolean)) item.is_technical = (bool)itemObject["is_technical"].GetBoolean();
                            if (itemObject["is_overtime"].ValueType.Equals(JsonValueType.Boolean)) item.is_overtime = (bool)itemObject["is_overtime"].GetBoolean();
                            if (itemObject["is_shootout"].ValueType.Equals(JsonValueType.Boolean)) item.is_shootout = (bool)itemObject["is_shootout"].GetBoolean();
                            JsonObject jsonObjectTeam = itemObject["team1"].GetObject();
                            FootballTeam _team1 = new FootballTeam((int)(jsonObjectTeam["id"].GetNumber()));
                            _team1.title = jsonObjectTeam["title"].GetString();
                            if (jsonObjectTeam["image_path"].ValueType.Equals(JsonValueType.String)) _team1.image_path = jsonObjectTeam["image_path"].GetString();
                            else _team1.image_path = "ms-appx:///Assets/noIm.png";
                            item.team1 = _team1;
                            jsonObjectTeam = itemObject["team2"].GetObject();
                            FootballTeam _team2 = new FootballTeam((int)(jsonObjectTeam["id"].GetNumber()));
                            _team2.title = jsonObjectTeam["title"].GetString();
                            if (jsonObjectTeam["image_path"].ValueType.Equals(JsonValueType.String)) _team2.image_path = jsonObjectTeam["image_path"].GetString();
                            else _team2.image_path = "ms-appx:///Assets/noIm.png";
                            item.team2 = _team2;
                            Addition ad = new Addition(9);
                            ad.attendance = 12;
                            item.addition = ad;
                            //past.Items.Add(item);
                            try { await GetItemsForMatch(item); }
                            catch (Exception ex)
                            {
                                DataSource.busy = false;
                                throw new Exception("Error aquired while loading data " + ex.Message);
                            }
                        }
                    }
                }
                if (_DataSource._tournaments.Count > 0)
                {
                    await Save();
                }
                else
                {
                    logout();
                }
            }
            catch (Exception ex)
            {
                busy = false;
                throw new Exception("Error aquired while loading data " + ex.Message);
            }
            finally
            {
                busy = false;
            }
            
        }
        private async Task<bool> GetItemsForMatch(FootballMatch match)
        {
            string UrlRound = DataSource.host + "round/";
            string UrlTournament = DataSource.host + "tournament/";
            Tournament t;
            Round r;

            Uri UriRound = new Uri(UrlRound + match.round_id.ToString() + "?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());
            //StorageFile fileRound = await StorageFile.GetFileFromApplicationUriAsync(UriRound);
            var responseR = await httpClient.GetAsync(UriRound);
            //try
            //{
            responseR.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultR = await responseR.Content.ReadAsStringAsync();
            JsonObject jsonObjectRound = JsonObject.Parse(resultR);


            Uri UriTrnmt = new Uri(UrlTournament + jsonObjectRound["tournament_id"].GetNumber().ToString() + "?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());
            var responseT = await httpClient.GetAsync(UriTrnmt);
            //try
            //{
            responseT.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultT = await responseT.Content.ReadAsStringAsync();
            JsonObject jsonObjectTournament = JsonObject.Parse(resultT);
            //StorageFile fileTournament = await StorageFile.GetFileFromApplicationUriAsync(UriTrnmt);
            //string jsonTextTournament = await FileIO.ReadTextAsync(fileTournament);
            //JsonObject jsonObjectTournament = JsonObject.Parse(jsonTextTournament);
            string impath = "";
            if (jsonObjectTournament["image_path"].ValueType.Equals(JsonValueType.String)) impath = jsonObjectTournament["image_path"].GetString();
            t = new Tournament((int)jsonObjectTournament["id"].GetNumber(), jsonObjectTournament["title"].GetString(), jsonObjectTournament["location"].GetString(), impath);
            r = new Round((int)jsonObjectRound["id"].GetNumber(), jsonObjectRound["name"].GetString(), (int)jsonObjectRound["tournament_id"].GetNumber());

            await GetProtocolItemsGroup(match, t);
            Tournament to = await GetTournamentAsync((int)jsonObjectRound["tournament_id"].GetNumber());
            Round ro = await GetRoundAsync(match.round_id);
            if (to == null)
            {

                r.Items.Add(match);
                t.RoundsList.Add(r);
                this.Tournaments.Add(t);
            }
            else if (ro == null)
            {
                r.Items.Add(match);
                to.RoundsList.Add(r);
            }
            else if (await GetItemAsync(match.id) == null)
            {
                ro.Items.Add(match);
            }
            return true;
        }
 private async Task<bool> GetProtocolItemsGroup(FootballMatch match, Tournament t)
 {
     await GetApplicant(match, t.id);
     await GetMatchPlayers(match.id, match);
     await GetYellowCards(match.id, match);
     await GetRedCards(match.id, match);
     await GetGoals(match.id, match);
     return true;
 }
        private async Task<bool> GetApplicant(FootballMatch match, int tournamentId)
        {
            //api.sportand.me:8000/team/16429/applicant?access_token=xxx&tournament_id=1728
            string urlApplicant = DataSource.host + "team/";
            Uri uriApplicantTeam1 = new Uri(urlApplicant + match.team1.id.ToString() + "/applicant?access_token=" + DataSource.accessToken + "&tournament_id=" + tournamentId.ToString() + "&" + Guid.NewGuid().ToString());
            Uri uriApplicantTeam2 = new Uri(urlApplicant + match.team2.id.ToString() + "/applicant?access_token=" + DataSource.accessToken + "&tournament_id=" + tournamentId.ToString() + "&" + Guid.NewGuid().ToString());
            var responseApplicantTeam1 = await httpClient.GetAsync(uriApplicantTeam1);
            //try
            //{
            responseApplicantTeam1.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultApplicantTeam1 = await responseApplicantTeam1.Content.ReadAsStringAsync();
            JsonObject jsonObjectApplicantTeam1 = JsonObject.Parse(resultApplicantTeam1);

            var responseApplicantTeam2 = await httpClient.GetAsync(uriApplicantTeam2);
            
            //try
            //{
            responseApplicantTeam2.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultApplicantTeam2 = await responseApplicantTeam2.Content.ReadAsStringAsync();
            JsonObject jsonObjectApplicantTeam2 = JsonObject.Parse(resultApplicantTeam2);
            //try
            //{
            JsonObject[] ja = new JsonObject[2];
            ja[0] = (jsonObjectApplicantTeam1);
            ja[1] = (jsonObjectApplicantTeam2);
            //JsonValue itemValue in groupObject["Items"].GetArray())
            //{
            //    JsonObject itemObject = itemValue.GetObject();
            for (int i = 0; i <= 1; i++)
            {
                JsonObject jsonObjectApplicant = ja[i];
                JsonArray jap = jsonObjectApplicant["rows"].GetArray();
                if (jap.Count > 0)
                {
                    foreach (JsonValue jsonValueApplicant in jap)
                    {
                        JsonObject rowObject = jsonValueApplicant.GetObject();
                        JsonObject japPlayer = rowObject["player"].GetObject();
                        String name = "";
                        String image_path = "";
                        String position = "";
                        int number = 0;
                        int gender = 1;
                        if (japPlayer["full_name"].ValueType.Equals(JsonValueType.String))
                        {
                            name = japPlayer["full_name"].GetString();
                        }
                        if (japPlayer["image_path"].ValueType.Equals(JsonValueType.String))
                        {
                            image_path = japPlayer["image_path"].GetString();
                        }
                        if (japPlayer["position"].ValueType.Equals(JsonValueType.String))
                        {
                            position = japPlayer["position"].GetString();
                        }
                        if (japPlayer["number"].ValueType.Equals(JsonValueType.Number))
                        {
                            number = (int)japPlayer["number"].GetNumber();
                        }
                        if (japPlayer["gender"].ValueType.Equals(JsonValueType.Number))
                        {
                            gender = (int)japPlayer["gender"].GetNumber();
                        }
                        Player p = new Player((int)japPlayer["id"].GetNumber(), name, image_path, position, gender, number);
                        if (i == 0)
                        {
                            match.team1_players.Add(p);
                        }
                        else
                        {
                            match.team2_players.Add(p);
                        }
                    }
                }
            }

            //}
            //catch (Exception ex)
            //{

            //}
            return true;
        }
        private async Task<HttpStatusCode> GetGoals(int matchId, FootballMatch match)
        {
            //•GET /match/<id>/yellow_card
            string urlRCPlayers = DataSource.host + "match/";
            Uri uriRCPlayers = new Uri(urlRCPlayers + match.id.ToString() + "/goal?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());

            var responseGoals = await httpClient.GetAsync(uriRCPlayers);
            //try
            //{
            responseGoals.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultGoals = await responseGoals.Content.ReadAsStringAsync();
            JsonObject jsonObjectGoals = JsonObject.Parse(resultGoals);

            //try
            //{
            JsonArray jap = jsonObjectGoals["rows"].GetArray();
            if (jap.Count > 0)
            {
                foreach (JsonValue jsonValueApplicant in jap)
                {
                    bool b = true;
                    JsonObject japMatchPlayer = jsonValueApplicant.GetObject();
                    int _id = 0;
                    int _match_id = 0;
                    int _team_id = 0;
                    int _player_id = 0;
                    int _minute = 0;
                    int _addition_minute = 0;
                    int _assistant_id = 0;
                    bool _is_penalty = false;
                    bool _is_autogoal = false;
                    if (japMatchPlayer["id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _id = (int)japMatchPlayer["id"].GetNumber();
                    }
                    if (japMatchPlayer["match_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _match_id = (int)japMatchPlayer["match_id"].GetNumber();
                    }
                    if (japMatchPlayer["team_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _team_id = (int)japMatchPlayer["team_id"].GetNumber();
                    }
                    if (japMatchPlayer["player_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _player_id = (int)japMatchPlayer["player_id"].GetNumber();
                    }
                    if (japMatchPlayer["assistant_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _assistant_id = (int)japMatchPlayer["assistant_id"].GetNumber();
                    }
                    if (japMatchPlayer["is_penalty"].ValueType.Equals(JsonValueType.Boolean))
                    {
                        _is_penalty = japMatchPlayer["is_penalty"].GetBoolean();
                    }
                    if (japMatchPlayer["is_autogoal"].ValueType.Equals(JsonValueType.Boolean))
                    {
                        _is_autogoal = japMatchPlayer["is_autogoal"].GetBoolean();
                    }
                    if (japMatchPlayer["minute"].ValueType.Equals(JsonValueType.Number))
                    {
                        _minute = (int)japMatchPlayer["minute"].GetNumber();
                    }
                    if (japMatchPlayer["addition_minute"].ValueType.Equals(JsonValueType.Number))
                    {
                        _addition_minute = (int)japMatchPlayer["addition_minute"].GetNumber();
                    }


                    Goal yc = new Goal(_id, _match_id, _team_id, _player_id, _assistant_id, _is_autogoal, _is_penalty, _minute, _addition_minute);
                    match.goals.Add(yc);
                }
            }
            //}
            //catch (Exception ex)
            //{

            //}
            return responseGoals.StatusCode;

        }
        private async Task<HttpStatusCode> GetYellowCards(int matchId, FootballMatch match)
        {
            //•GET /match/<id>/yellow_card
            string urlMatchPlayers = DataSource.host + "match/";
            Uri uriMatchPlayers = new Uri(urlMatchPlayers + match.id.ToString() + "/yellow_card?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());
            var responseMatchPlayers = await httpClient.GetAsync(uriMatchPlayers);
            //try
            //{
            responseMatchPlayers.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultMatchPlayers = await responseMatchPlayers.Content.ReadAsStringAsync();
            JsonObject jsonObjectMatchPlayers = JsonObject.Parse(resultMatchPlayers);
            //try
            //{
            JsonArray jap = jsonObjectMatchPlayers["rows"].GetArray();
            if (jap.Count > 0)
            {
                foreach (JsonValue jsonValueApplicant in jap)
                {
                    bool b = true;
                    JsonObject japMatchPlayer = jsonValueApplicant.GetObject();
                    int _id = 0;
                    int _match_id = 0;
                    int _team_id = 0;
                    int _player_id = 0;
                    int _minute = 0;
                    int _addition_minute = 0;
                    string _note = "";
                    if (japMatchPlayer["id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _id = (int)japMatchPlayer["id"].GetNumber();
                    }
                    if (japMatchPlayer["match_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _match_id = (int)japMatchPlayer["match_id"].GetNumber();
                    }
                    if (japMatchPlayer["team_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _team_id = (int)japMatchPlayer["team_id"].GetNumber();
                    }
                    if (japMatchPlayer["player_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _player_id = (int)japMatchPlayer["player_id"].GetNumber();
                    }
                    if (japMatchPlayer["minute"].ValueType.Equals(JsonValueType.Number))
                    {
                        _minute = (int)japMatchPlayer["minute"].GetNumber();
                    }
                    if (japMatchPlayer["addition_minute"].ValueType.Equals(JsonValueType.Number))
                    {
                        _addition_minute = (int)japMatchPlayer["addition_minute"].GetNumber();
                    }
                    if (japMatchPlayer["note"].ValueType.Equals(JsonValueType.String))
                    {
                        _note = japMatchPlayer["note"].GetString();
                    }

                    YellowCard yc = new YellowCard(_id, _match_id, _team_id, _player_id, _minute, _addition_minute, _note);
                    match.yellowcards.Add(yc);
                }
            }
            //}
            //catch (Exception ex)
            //{

            //}
            return responseMatchPlayers.StatusCode;

        }
        private async Task<HttpStatusCode> GetMatchPlayers(int matchId, FootballMatch match)
        {
            //api.sportand.me:8000/team/16429/applicant?access_token=xxx&tournament_id=1728
            string urlMatchPlayers = DataSource.host + "match/";
            Uri uriMatchPlayers = new Uri(urlMatchPlayers + match.id.ToString() + "/match_player?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());

            var responseMatchPlayers = await httpClient.GetAsync(uriMatchPlayers);
            //try
            //{
            responseMatchPlayers.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultMatchPlayers = await responseMatchPlayers.Content.ReadAsStringAsync();
            JsonObject jsonObjectMatchPlayers = JsonObject.Parse(resultMatchPlayers);

            //try
            //{
            JsonArray jap = jsonObjectMatchPlayers["rows"].GetArray();
            if (jap.Count > 0)
            {
                foreach (JsonValue jsonValueApplicant in jap)
                {
                    JsonObject japMatchPlayer = jsonValueApplicant.GetObject();
                    int _match_id = 0;
                    int _team_id = 0;
                    int _player_id = 0;
                    int _id = 0;
                    int _teamsheet = 0;
                    bool _isCaptain = false;
                    bool _isGoalkeeper = false;
                    if (japMatchPlayer["id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _id = (int)japMatchPlayer["id"].GetNumber();
                    }
                    if (japMatchPlayer["match_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _match_id = (int)japMatchPlayer["match_id"].GetNumber();
                    }
                    if (japMatchPlayer["team_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _team_id = (int)japMatchPlayer["team_id"].GetNumber();
                    }
                    if (japMatchPlayer["player_id"].ValueType.Equals(JsonValueType.Number))
                    {
                        _player_id = (int)japMatchPlayer["player_id"].GetNumber();
                    }
                    if (japMatchPlayer["teamsheet"].ValueType.Equals(JsonValueType.Number))
                    {
                        _teamsheet = (int)japMatchPlayer["teamsheet"].GetNumber();
                    }
                    if (japMatchPlayer["is_capitan"].ValueType.Equals(JsonValueType.Boolean))
                    {
                        _isCaptain = japMatchPlayer["is_capitan"].GetBoolean();
                    } if (japMatchPlayer["is_goalkeeper"].ValueType.Equals(JsonValueType.Boolean))
                    {
                        _isGoalkeeper = japMatchPlayer["is_goalkeeper"].GetBoolean();
                    }

                    MatchPlayer mp = new MatchPlayer(_id, _match_id, _team_id, _player_id);
                    mp.TeamsheetValue = _teamsheet;
                    mp.Is_capitanValue = _isCaptain;
                    mp.Is_goalkeeperValue = _isGoalkeeper;
                    match.matchPlayers.Add(mp);
                }
            }
            //}
            //catch (Exception ex)
            //{

            //}
            return responseMatchPlayers.StatusCode;

        }
 public DataGroupYCPlayers(FootballMatch match, FootballTeam team, Player player, YellowCard yellowCard)
 {
     this.match = match;
     this.team = team;
     this.player = player;
     this.yellowCard = yellowCard;
 }
        private async Task <bool> Get()
        {
            FootballMatch fm = await DataSource.GetItemAsync(this.match_id);

            HttpClient httpClient      = new HttpClient();
            string     urlMatchPlayers = DataSource.host + "match/";
            Uri        uriMatchPlayers = new Uri(urlMatchPlayers + this.match_id.ToString() + "/match_player?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());

            var responseMatchPlayers = await httpClient.GetAsync(uriMatchPlayers);

            try
            {
                responseMatchPlayers.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                return(false);
            }
            string resultMatchPlayers = await responseMatchPlayers.Content.ReadAsStringAsync();

            JsonObject jsonObjectMatchPlayers = JsonObject.Parse(resultMatchPlayers);

            try
            {
                JsonArray jap = jsonObjectMatchPlayers["rows"].GetArray();
                if (jap.Count > 0)
                {
                    foreach (JsonValue jsonValueApplicant in jap)
                    {
                        bool       b = true;
                        JsonObject japMatchPlayer = jsonValueApplicant.GetObject();
                        int        _id            = 0;
                        int        _match_id      = 0;
                        int        _team_id       = 0;
                        if (japMatchPlayer["id"].ValueType.Equals(JsonValueType.Number))
                        {
                            _id = (int)japMatchPlayer["id"].GetNumber();
                        }
                        if (japMatchPlayer["match_id"].ValueType.Equals(JsonValueType.Number))
                        {
                            _match_id = (int)japMatchPlayer["match_id"].GetNumber();
                        }
                        if (japMatchPlayer["team_id"].ValueType.Equals(JsonValueType.Number))
                        {
                            _team_id = (int)japMatchPlayer["team_id"].GetNumber();
                        }
                        foreach (MatchPlayer mpl in fm.matchPlayers)
                        {
                            if (mpl.id == _id)
                            {
                                b = false;
                            }
                        }
                        if (b && _match_id == this.match_id)
                        {
                            if (_team_id == this.team_id)
                            {
                                this.id = _id;
                                fm.matchPlayers.Add(this);
                            }
                        }
                    }
                }
            }


            catch (Exception ex)
            {
            }
            return(true);
        }