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 StudentData GetStudent(int StudentID) { var student = new StudentData(); using (SchoolDB db = new SchoolDB()) { var studentDB = db.Student.Find(StudentID); student.ID = studentDB.StudentID; student.Name = studentDB.StudentName; } return(student); }
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(); } } }
public List <StudentData> GetStudents() { var lista = new List <StudentData>(); using (SchoolDB db = new SchoolDB()) { //LINQ query to get students var listaDB = (from p in db.Student select p).ToList(); foreach (var item in listaDB) { lista.Add(new StudentData() { ID = item.StudentID, Name = item.StudentName }); } } return(lista); }