public void CreateStudent(Student student) { using (SchoolDB db = new SchoolDB()) { db.Student.Add(student); db.SaveChanges(); } }
public void UpdateStudent(StudentData student) { using (SchoolDB db = new SchoolDB()) { var EditedObj = db.Student.Find(student.ID); if (EditedObj != null)//if student is found { EditedObj.StudentName = student.Name; db.SaveChanges(); } } }
public void DeleteStudent(int StudentID) { using (SchoolDB db = new SchoolDB()) { var EditedObj = db.Student.Find(StudentID); if (EditedObj != null) { var classes = db.Class.Where(x => x.StudentID == StudentID); foreach (var classe in classes) { classe.StudentID = null; } db.Student.Remove(EditedObj); db.SaveChanges(); } } }