Example #1
0
 public void CreateStudent(Student student)
 {
     using (SchoolDB db = new SchoolDB())
     {
         db.Student.Add(student);
         db.SaveChanges();
     }
 }
Example #2
0
        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();
                }
            }
        }
Example #3
0
        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();
                }
            }
        }