public void DeleteStudent(int studentId)
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var student = con.Students.Where(x => x.StudentId == studentId).FirstOrDefault();
         if (student != null) {
             con.Students.Remove(student);
             con.SaveChanges();
         }
     }
 }
 public void DeleteEnrollment(int courseId, int studentId)
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var enrollment = con.Enrollments.Where(x => x.CourseId == courseId && x.StudentId == studentId).FirstOrDefault();
         if (enrollment != null) {
             con.Enrollments.Remove(enrollment);
             con.SaveChanges();
         }
     }
 }
 public void DeleteCourse(int courseId)
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var course = con.Courses.Where(x => x.CourseId == courseId).FirstOrDefault();
         if (course != null) {
             con.Courses.Remove(course);
             con.SaveChanges();
         }
     }
 }
 public void DeleteAll()
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var students = con.Students;
         if (students != null) {
             foreach (var s in students) {
                 con.Students.Remove(s);
             }
             con.SaveChanges();
         }
     }
 }
 public void AddStudent(StudentData studentData)
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var student = new Student {
             FirstName = studentData.FirstName,
             LastName = studentData.LastName,
             DateCreated = studentData.DateCreated
         };
         con.Students.Add(student);
         con.SaveChanges();
     }
 }
 public void DeleteAll()
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var enrollments = con.Enrollments;
         if (enrollments != null) {
             foreach (var e in enrollments) {
                 con.Enrollments.Remove(e);
             }
             con.SaveChanges();
         }
     }
 }
        public void AddEnrollment(EnrollmentData enrollmentData)
        {
            using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {

                var enrollment = new Enrollment {
                    CourseId = enrollmentData.CourseId,
                    StudentId = enrollmentData.StudentId
                };
                con.Enrollments.Add(enrollment);
                con.SaveChanges();
            }
        }
 public void DeleteAll()
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var courses = con.Courses;
         if (courses != null) {
             foreach (var c in courses) {
                 con.Courses.Remove(c);
             }
             con.SaveChanges();
         }
     }
 }
 public void AddCourse(CourseData courseData)
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var course = new Course {
             Title = courseData.Title,
             StartDate = courseData.StartDate,
             MaxEnrollmentCount = courseData.MaxEnrollmentCount
         };
         con.Courses.Add(course);
         con.SaveChanges();
     }
 }
        public bool UpdateStudent(StudentData studentData)
        {
            using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
                var student = con.Students.Where(x => x.StudentId == studentData.StudentId).FirstOrDefault();
                if (student != null) {
                    student.FirstName = studentData.FirstName;
                    student.LastName = studentData.LastName;
                    student.DateCreated = studentData.DateCreated;

                    con.SaveChanges();
                    return true;
                }
            }
            return false;
        }
 public bool UpdateEnrollment(EnrollmentData enrollmentData)
 {
     using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
         var enrollment = con.Enrollments.Where(x => x.EnrollmentId == enrollmentData.EnrollmentId).FirstOrDefault();
         if (enrollment != null) {
             enrollment.StudentId = enrollmentData.StudentId;
             enrollment.CourseId = enrollmentData.CourseId;
             con.SaveChanges();
             return true;
         }
     }
     return false;
 }
        public bool UpdateCourse(CourseData courseData)
        {
            using (KaplanTestPrepEntities con = new KaplanTestPrepEntities()) {
                var course = con.Courses.Where(x => x.CourseId == courseData.CourseId).FirstOrDefault();
                if (course != null) {
                    course.Title = courseData.Title;
                    course.StartDate = courseData.StartDate;
                    course.MaxEnrollmentCount = courseData.MaxEnrollmentCount;

                    con.SaveChanges();
                    return true;
                }
            }
            return false;
        }