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; ActiveDataGroupGoalItem.firstTeam = true; } else { ft = ((FootballMatch)this.DefaultViewModel["Match"]).team2; ActiveDataGroupGoalItem.firstTeam = false; } ActiveDataGroupGoalItem.goal.Player_idValue = p.id; ActiveDataGroupGoalItem.player = p; ActiveDataGroupGoalItem.team = ft; ActiveDataGroupGoalItem.goal.Team_idValue = ft.id; int iM = 0; int iAM = 0; try { iM = Int32.Parse(MinuteTextBox.Text); iAM = Int32.Parse(AdditionMinuteTextBox.Text); } catch { iM = 0; iAM = 0; } ActiveDataGroupGoalItem.goal.MinuteValue = iM; ActiveDataGroupGoalItem.goal.Addition_minuteValue = iAM; if (AssistantComboBoxEd.SelectedIndex != -1) ActiveDataGroupGoalItem.goal.Assistant_idValue = ((Player)AssistantComboBoxEd.SelectedItem).id; else ActiveDataGroupGoalItem.goal.Assistant_idValue = 0; ActiveDataGroupGoalItem.goal.Is_penaltyValue = (bool)IsPenaltyEd.IsChecked; ActiveDataGroupGoalItem.goal.Is_autogoalValue = (bool)IsAutogoalEd.IsChecked; ActiveDataGroupGoalItem.goal.objectStatus = (int)DataSource.status.needUpdate; await ActiveDataGroupGoalItem.goal.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 { if(iM == null)iM = 0; if(iAM == null)iAM = 0; } int t = 0; if (AssistantComboBoxEd.SelectedIndex != -1) t = ((Player)AssistantComboBoxEd.SelectedItem).id; Goal mp = new Goal(0, ((FootballMatch)this.DefaultViewModel["Match"]).id, ft.id, ((Player)PlayerComboBoxEd.SelectedItem).id, t, (bool)IsAutogoalEd.IsChecked, (bool)IsPenaltyEd.IsChecked, iM, iAM); 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) { DataGroupGoalsPlayers dgm = new DataGroupGoalsPlayers(fm, ft, ((Player)PlayerComboBoxEd.SelectedItem), mp); if (first) { dgm.assName = "Не было помощника"; dgm.firstTeam = true; foreach (Player ass in ((FootballMatch)this.DefaultViewModel["Match"]).team1_players) { if (ass.id == dgm.goal.Assistant_idValue) { dgm.assName = ass.full_name; } } } else { dgm.assName = "Не было помощника"; dgm.firstTeam = false; foreach (Player ass in ((FootballMatch)this.DefaultViewModel["Match"]).team2_players) { if (ass.id == dgm.goal.Assistant_idValue) { dgm.assName = ass.full_name; } } } //this.DefaultViewModel["Team1MatchPlayers"] = dataGroupsGoalsPlayer.Where((team) => team.team.id.Equals(fm.team1.id)); //this.DefaultViewModel["Team2MatchPlayers"] = dataGroupsGoalsPlayer.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("Успешно сохранено на сервере."); await DataSource.Save(); dialog.ShowAsync(); } catch (Exception ex) { var dialog = new MessageDialog("Не удалось сохранить данные на сервере."); dialog.ShowAsync(); } finally { LoadState(); synchProgressRing.IsActive = false; loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Collapsed; if (TeamComboBox.SelectedIndex == 0) { if (this.DefaultViewModel.ContainsKey("Team1MatchPlayers")) mainListView.ItemsSource = this.DefaultViewModel["Team1MatchPlayers"]; } else { if (this.DefaultViewModel.ContainsKey("Team2MatchPlayers")) mainListView.ItemsSource = this.DefaultViewModel["Team2MatchPlayers"]; } } }
public DataGroupGoalsPlayers(FootballMatch match, FootballTeam team, Player player, Goal goal) { this.match = match; this.team = team; this.player = player; this._goals = goal; }
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; }