private void deletebtn_Click(object sender, EventArgs e) { MsgBoxDialog md = new MsgBoxDialog(); DialogResult result = md.Showw("Deleting Course Will Delete following data as well!\n1. All the Student with same course.\n2. All the Subjects within the course."); if (result == DialogResult.OK) { AspireDB db = new AspireDB(); Course x = db.Courses.SingleOrDefault(Course => Course.CourseID == _cs.CourseID && Course.Name == _cs.Name && Course.Level == _cs.Level); // Deleting Cources foreach (Subject s in db.Subjects.Where(Subject => Subject.CourseID == x.CourseID)) { db.Entry(s).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); // Deleting Students foreach (Student s in db.Students.Where(Student => Student.CourseID == x.CourseID)) { db.Entry(s).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); // Deleting Course db.Entry(x).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); // SubjectControl.Instance.CreateList(); SubjectControl.Instance.FilterBoxUpdate(); SubjectControl.Instance.FooterMessage(x.Name + " Deleted -> Subjects Deleted "); StudentControl.Instance.CreateList(); StudentControl.Instance.FooterMessage(x.Name + " Deleted -> Students Deleted "); CourseControl.Instance.FooterMessage("Course Deleted"); CourseControl.Instance.CreateList(); } else { } }
private void deletebtn_Click(object sender, EventArgs e) { MsgBoxDialog md = new MsgBoxDialog(); DialogResult result = md.Showw("Are you sure ?"); if (result == DialogResult.OK) { try { AspireDB db = new AspireDB(); Level l = db.Levels.SingleOrDefault(x => x.LevelName == _lvl.LevelName); db.Levels.Remove(l); db.SaveChanges(); LevelControl.Instance.CreateList(); LevelControl.Instance.FooterMessage(l.LevelName + " Deleted"); } catch (Exception ee) { MsgBoxDialog md2 = new MsgBoxDialog(); DialogResult res = md2.Showw("Failed to Delete Level !"); } } }