/// <summary> /// Event handler for adding player button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void add_Button_Click(object sender, EventArgs e) { //Creating and showing of players editor window form as dialog. PlayerEditor editor = new PlayerEditor (context.Players.Local.ToBindingList() , context.Teams.Local.ToBindingList()); DialogResult result = editor.ShowDialog(this); if (result == DialogResult.Cancel) { return; } //Choosing of a team. //If that team doesn't exists - creating a new one. Team team; //int teamId = (int)editor.team_comboBox.SelectedValue; if (/*context.Teams.Find(teamId)*/ editor.team_comboBox.SelectedValue is null) { team = new Team { Name = editor.team_comboBox.Text }; context.Teams.Add(team); context.SaveChanges(); } else { team = (Team)editor.team_comboBox.SelectedItem; } //Creating of a new player. Player player = new Player { Name = editor.name_textBox.Text, Age = (int)editor.age_numericUpDown.Value, Position = editor.position_comboBox.Text, Team = team }; context.Players.Add(player); context.SaveChanges(); players_DataGridView.Refresh(); }
private void add_Button_Click(object sender, EventArgs e) { TeamEditor editor = new TeamEditor(); DialogResult result = editor.ShowDialog(this); if (result == DialogResult.Cancel) { return; } context.Teams.Add ( new Team { Name = editor.name_textBox.Text, Couch = editor.couch_TextBox.Text == string.Empty ? null : editor.couch_TextBox.Text } ); context.SaveChanges(); teams_DataGridView.Refresh(); }