private void buttonOEKaydet_Click(object sender, EventArgs e) { Branch branch = comboBoxOEBrans.SelectedItem as Branch; if (branch == null) { MessageBox.Show("Branş seçilmelidir."); return; } Teacher teacher = new Teacher { Name = textBoxOKAd.Text, Surname = textBoxOESoyad.Text, BirthDate = dateTimePickerOEBDate.Value, BranchId = branch.Id }; EfContext efContext = new EfContext(); efContext.Teachers.Add(teacher); try { efContext.SaveChanges(); MessageBox.Show("Kaydedildi"); } catch (Exception exception) { MessageBox.Show("Kaydedilmedi"); } }
private void buttonBGuncelleme_Click(object sender, EventArgs e) { branchEditing.Name = textBoxBGAd.Text; EfContext efContext = new EfContext(); Branch originBranch = efContext.Branches.FirstOrDefault(b => b.Id == branchEditing.Id); efContext.Entry(originBranch).CurrentValues.SetValues(branchEditing); try { efContext.SaveChanges(); MessageBox.Show("Kaydedildi"); } catch (Exception exception) { MessageBox.Show("Kaydedilmedi"); } }
private void buttonBSil_Click(object sender, EventArgs e) { if (branchEditing == null) { MessageBox.Show("Silinecek branş bulunmadı"); return; } EfContext efContext = new EfContext(); efContext.Branches.Remove(efContext.Branches.Find(branchEditing.Id)); try { efContext.SaveChanges(); MessageBox.Show("Silindi"); } catch (Exception exception) { MessageBox.Show("Silinmedi"); } }
private void buttonBEkleme_Click(object sender, EventArgs e) { Branch branch = new Branch { Name = textBoxBEkleme.Text }; EfContext efContext = new EfContext(); efContext.Branches.Add(branch); try { efContext.SaveChanges(); MessageBox.Show("Kaydedildi"); } catch (Exception exception) { MessageBox.Show("Kaydedilmedi"); } efContext.Dispose(); }