public bool UpdateStudentSchedule(StudentSchedule schedule, EntityState state)
        {
            var entry = db.Entry <StudentSchedule>(schedule);

            entry.State = state;
            return(db.SaveChanges() > 0);
        }
        /// <summary>
        /// Create a new StudentSchedule with the given Enrolled value.
        /// </summary>
        /// <param name="student"></param>
        /// <param name="courseSchedule"></param>
        /// <param name="enrolled"></param>
        /// <returns></returns>
        private bool CreateStudentSchedule(Student student, CourseSchedule courseSchedule, bool enrolled)
        {
            bool successful = CanRegisterForCourse(student, courseSchedule);

            if (successful)
            {
                StudentSchedule existingSchedule = db.StudentSchedules.Where(s => s.StudentId == student.PersonId && s.CourseScheduleId == courseSchedule.CourseScheduleId).FirstOrDefault();

                if (existingSchedule == null)
                {
                    db.StudentSchedules.Add(new StudentSchedule
                    {
                        Student        = student,
                        CourseSchedule = courseSchedule,
                        Enrolled       = enrolled
                    });
                }
                else
                {
                    existingSchedule.Enrolled = enrolled;
                    var entry = db.Entry(existingSchedule);
                    entry.State = EntityState.Modified;
                }

                successful = db.SaveChanges() > 0;
            }

            return(successful);
        }
        /// <summary>
        /// Drop a Student's course.
        /// </summary>
        /// <param name="student">The Student to drop the Course from.</param>
        /// <param name="studentSchedule">The Course to drop.</param>
        /// <returns>True if the drop was successful.</returns>
        public bool DropCourse(Student student, StudentSchedule studentSchedule)
        {
            bool successful = db.StudentSchedules.Remove(studentSchedule) != null;

            if (successful)
            {
                successful = db.SaveChanges() > 0;
            }

            return(successful);
        }
Beispiel #4
0
 public bool RemoveStudentSchedule(StudentSchedule schedule)
 {
     db.StudentSchedules.Remove(schedule);
     return(db.SaveChanges() > 0);
 }
Beispiel #5
0
 public bool InsertStudentSchedule(StudentSchedule schedule)
 {
     db.StudentSchedules.Add(schedule);
     return(db.SaveChanges() > 0);
 }