private void button1_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); using (PersonCrudEntities db = new PersonCrudEntities()) { person isExests = db.people.FirstOrDefault(r => r.email == textBoxEmail.Text); if (isExests == null) { person aPerson = new person { name = textBoxName.Text, email = textBoxEmail.Text }; //is email exists or not db.people.Add(aPerson); db.SaveChanges(); MessageBox.Show("data saved !"); } else { MessageBox.Show("email already exists."); } showAllData(); } }
private void buttonUpdate_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); if (textBoxId.Text != "") { using (PersonCrudEntities db = new PersonCrudEntities()) { int id = Convert.ToInt32(textBoxId.Text); person isExests = db.people.FirstOrDefault(r => r.email == textBoxEmail.Text); person aPerson = db.people.FirstOrDefault(r => r.ID == id); if (isExests == null) { aPerson.name = textBoxName.Text; aPerson.email = textBoxEmail.Text; //is email exists or not //db.people.Add(aPerson); db.SaveChanges(); MessageBox.Show("Updated Successfully !"); } else { MessageBox.Show("email already exists."); } } } else { MessageBox.Show("Please Select a member for update."); } showAllData(); }
private void buttonDelete_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); if (textBoxId.Text != "") { using (PersonCrudEntities db = new PersonCrudEntities()) { int id = Convert.ToInt32(textBoxId.Text); person aPerson = db.people.FirstOrDefault(r => r.ID == id); db.people.Remove(aPerson); db.SaveChanges(); MessageBox.Show("Deleted successfully !"); } } else { MessageBox.Show("Please select a Member for delete."); } showAllData(); }