private void btnsave_Click(object sender, EventArgs e) { using (dbconection db = new dbconection()) { Grade grade = new Grade(); grade.Name = txtname.Text; grade.TeacherId = Convert.ToInt32(cmbteacher.SelectedValue); db.Grades.Add(grade); db.SaveChanges(); } }
private void btndelete_Click(object sender, EventArgs e) { int?id = GetId(); using (dbconection database = new dbconection()) { Teacher teacher = database.Teachers.Find(id); database.Teachers.Remove(teacher); database.SaveChanges(); } CleanTxt(); GetTeachers(); }
private void btnsave_Click(object sender, EventArgs e) { using (dbconection db = new dbconection()) { Teacher teacher = new Teacher(); teacher.Name = txtname.Text; teacher.LastName = txtlastname.Text; teacher.Gender = cmbgender.Text; db.Teachers.Add(teacher); db.SaveChanges(); CleanTxt(); } GetTeachers(); }
private void btnedit_Click(object sender, EventArgs e) { int?id = GetId(); using (dbconection database = new dbconection()) { Teacher teacher = null; teacher = database.Teachers.Find(id); teacher.Name = txtname.Text; teacher.LastName = txtlastname.Text; teacher.Gender = cmbgender.Text; database.Entry(teacher).State = System.Data.Entity.EntityState.Modified; database.SaveChanges(); } GetTeachers(); }