private void Delete_Click(object sender, MouseEventArgs e, ClassModel model) { var confirmResult = MessageBox.Show("Are you sure you want to delete this class?", "Confirm Delete", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { ClassController ccontroller = new ClassController(); try { AttendanceController acontroller = new AttendanceController(); acontroller.DeleteAllByClass(model.Id); ccontroller.Delete(model); MessageBox.Show("Deleted!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }