Example #1
0
        //add
        private void button1_Click(object sender, EventArgs e)
        {
            PlayerAdd plForm = new PlayerAdd();


            // make list from teams

            List <Team> teams = db.Teams.ToList();

            plForm.comboBox2.DataSource    = teams;
            plForm.comboBox2.ValueMember   = "Id";
            plForm.comboBox2.DisplayMember = "Name";

            DialogResult result = plForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Player pl = new Player();

            pl.Age      = (int)plForm.numericUpDown1.Value;
            pl.Name     = plForm.textBox1.Text;
            pl.Position = plForm.comboBox1.SelectedItem.ToString();
            pl.Team     = (Team)plForm.comboBox2.SelectedItem;


            db.Players.Add(pl);
            db.SaveChanges();

            MessageBox.Show("Footballer added");
        }
Example #2
0
        //add
        private void button1_Click(object sender, EventArgs e)
        {
            TeamForm     tf     = new TeamForm();
            DialogResult result = tf.ShowDialog(this);


            if (tf.DialogResult == DialogResult.Cancel)
            {
                return;
            }
            Team team = new Team();

            team.Name  = tf.textBox1.Text;
            team.Coach = tf.textBox2.Text;
            db.Teams.Add(team);
            db.SaveChanges();
            MessageBox.Show("Team addded");
        }