示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Classroom c = new Classroom();
            c.Name = txtName.Text;
            c.NumberOfClasses = Convert.ToInt16(txtClassNum.Text);

            try
            {
                _classroomDatalayer.Save(c);
                dgClassrooms.DataSource = null;
                dgClassrooms.DataSource = _classroomDatalayer.ClassroomList;

                txtName.Text = string.Empty;
                txtClassNum.Text = string.Empty;
                txtName.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public void Save(Classroom classroomToSave)
 {
     _entitiesDb.Classroom.Add(classroomToSave);
     _entitiesDb.SaveChanges();
     _classroomList.Add(classroomToSave);
 }