private async void AcceptButtonEd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                synchProgressRing.IsActive = true;
                loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Visible;
                if (PlayerComboBoxEd.SelectedItem != null && TeamComboBoxEd.SelectedItem != null)
                {
                    if (PlayerComboBoxEd.SelectedItem.GetType().Equals(typeof(Player)))
                    {
                        if (editorPanel.Tag.ToString() == "Edit")
                        {

                            Player p = (Player)PlayerComboBoxEd.SelectedItem;
                            FootballTeam ft;
                            if (TeamComboBoxEd.SelectedIndex == 0)
                            {
                                ft = ((FootballMatch)this.DefaultViewModel["Match"]).team1;
                                ActiveDataGroupRCPlayersItem.firstTeam = true;
                            }
                            else
                            {
                                ft = ((FootballMatch)this.DefaultViewModel["Match"]).team2;
                                ActiveDataGroupRCPlayersItem.firstTeam = false;
                            }
                            ActiveDataGroupRCPlayersItem.redCard.Player_idValue = p.id;
                            ActiveDataGroupRCPlayersItem.player = p;
                            ActiveDataGroupRCPlayersItem.team = ft;
                            ActiveDataGroupRCPlayersItem.redCard.Team_idValue = ft.id;
                            int iM = 0;
                            int iAM = 0;
                            try
                            {
                                iM = Int32.Parse(MinuteTextBox.Text);
                                iAM = Int32.Parse(AdditionMinuteTextBox.Text);
                            }
                            catch
                            {
                                if(iM == null)iM = 0;
                                if(iAM == null) iAM = 0;
                            }
                            ActiveDataGroupRCPlayersItem.redCard.MinuteValue = iM;
                            ActiveDataGroupRCPlayersItem.redCard.Addition_minuteValue = iAM;
                            ActiveDataGroupRCPlayersItem.redCard.NoteValue = NoteTextBox.Text;
                            ActiveDataGroupRCPlayersItem.redCard.Is_two_yellowValue = (bool)IsTwoYellowCardEd.IsChecked;
                            ActiveDataGroupRCPlayersItem.redCard.objectStatus = (int)DataSource.status.needUpdate;
                            await ActiveDataGroupRCPlayersItem.redCard.Update();


                        }
                        else
                        {
                            FootballTeam ft;
                            bool first;
                            if (TeamComboBoxEd.SelectedIndex == 0)
                            {
                                ft = ((FootballMatch)this.DefaultViewModel["Match"]).team1;
                                first = true;
                            }
                            else
                            {
                                ft = ((FootballMatch)this.DefaultViewModel["Match"]).team2;
                                first = false;
                            }
                            int iM = 0;
                            int iAM = 0;
                            try
                            {
                                iM = Int32.Parse(MinuteTextBox.Text);
                                iAM = Int32.Parse(AdditionMinuteTextBox.Text);
                            }
                            catch
                            {
                                iM = 0;
                                iAM = 0;
                            }
                            RedCard mp = new RedCard(0, ((FootballMatch)this.DefaultViewModel["Match"]).id, ft.id, ((Player)PlayerComboBoxEd.SelectedItem).id, (bool)IsTwoYellowCardEd.IsChecked, iM, iAM, NoteTextBox.Text);
                            mp.objectStatus = (int)DataSource.status.needCreate;
                           await mp.Update();

                            //FootballMatch fm = await DataSource.GetItemAsync(activId);
                            // if (mp.objectStatus != (int)DataSource.status.Deleted || mp.objectStatus != (int)DataSource.status.needDelete)
                            //{
                            //    DataGroupRCPlayers dgm = new DataGroupRCPlayers(fm, ft, ((Player)PlayerComboBoxEd.SelectedItem), mp);
                            //     if (first)
                            //     {
                            //         dgm.firstTeam = true;
                            //     }
                            //     else
                            //     {
                            //         dgm.firstTeam = false;
                            //    }
                            // dataGroupsRCPlayer.Add(dgm);
                            // this.DefaultViewModel["dataGroupsMatchPlayer"] = dataGroupsRCPlayer;
                            // this.DefaultViewModel["Team1MatchPlayers"] = dataGroupsRCPlayer.Where((team) => team.team.id.Equals(fm.team1.id));
                            // this.DefaultViewModel["Team2MatchPlayers"] = dataGroupsRCPlayer.Where((team) => team.team.id.Equals(fm.team2.id));
                            //}
                            //Frame.Navigate(typeof(MatchPlayerPage), activId);
                        }
                        viewPanel.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        editorPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        DeleteButtonEd.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    }
                    
                }
                var dialog = new MessageDialog("Успешно сохранено на сервере.");
                dialog.ShowAsync();
                await DataSource.Save();
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog("Не удалось сохранить данные на сервере.");
                dialog.ShowAsync();
            }
            finally
            {
                LoadState();
                synchProgressRing.IsActive = false;
                loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
        }
 public DataGroupRCPlayers(FootballMatch match, FootballTeam team, Player player, RedCard redCard)
 {
     this.match = match;
     this.team = team;
     this.player = player;
     this.redCard = redCard;
 }
        private async Task<HttpStatusCode> GetRedCards(int matchId, FootballMatch match)
        {
            //•GET /match/<id>/yellow_card
            string urlRCPlayers = DataSource.host + "match/";
            Uri uriRCPlayers = new Uri(urlRCPlayers + match.id.ToString() + "/red_card?access_token=" + DataSource.accessToken + "&" + Guid.NewGuid().ToString());

            var responseRCPlayers = await httpClient.GetAsync(uriRCPlayers);
            //try
            //{
            responseRCPlayers.EnsureSuccessStatusCode();
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            string resultRCPlayers = await responseRCPlayers.Content.ReadAsStringAsync();
            JsonObject jsonObjectRCPlayers = JsonObject.Parse(resultRCPlayers);
            //try
            //{
            JsonArray jap = jsonObjectRCPlayers["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;
                    bool _is_two_yellow = false;
                    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["is_two_yellow"].ValueType.Equals(JsonValueType.Boolean))
                    {
                        _is_two_yellow = japMatchPlayer["is_two_yellow"].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();
                    }
                    if (japMatchPlayer["note"].ValueType.Equals(JsonValueType.String))
                    {
                        _note = japMatchPlayer["note"].GetString();
                    }

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

            //}
            return responseRCPlayers.StatusCode;

        }