Esempio n. 1
0
        public static CourseSessionDAO MapToCourseSessionDAO(CourseSession sessionToMap)
        {
            CourseSessionDAO courseSession = new CourseSessionDAO();

            courseSession.Id            = sessionToMap.Id;
            courseSession.CourseId      = sessionToMap.CourseId;
            courseSession.Capacity      = sessionToMap.Capacity;
            courseSession.DaysInSession = sessionToMap.DaysInSession;
            courseSession.StartTime     = sessionToMap.StartTime;
            courseSession.EndTime       = sessionToMap.EndTime;
            courseSession.Professor     = sessionToMap.Professor;

            return(courseSession);
        }
Esempio n. 2
0
        public bool RemoveSession(CourseSession session)
        {
            var matchingSessions = db.CourseSessions.Where(cs => cs.Id.Equals(session.Id));

            if (matchingSessions.Count() > 0)
            {
                db.CourseSessions.Remove(matchingSessions.First());
                return(db.SaveChanges() > 0);
            }

            else
            {
                Debug.WriteLine("Course does not exist.");
                return(false);
            }
        }
Esempio n. 3
0
        public bool InsertSession(CourseSession session)
        {
            var matchingCourses = db.Courses.Where(s => s.Id.Equals(session.CourseId));

            if (matchingCourses.Count() == 1)
            {
                db.CourseSessions.Add(session);
                return(db.SaveChanges() > 0);
            }

            else
            {
                Debug.WriteLine("Invalid course id.");
                return(false);
            }
        }
Esempio n. 4
0
        public bool UpdateSessionCapacity(int newCapacity, int sessionId)
        {
            var matchingSessions = db.CourseSessions.Where(cs => cs.Id.Equals(sessionId));

            if (matchingSessions.Count() > 0)
            {
                CourseSession sessionToUpdate = matchingSessions.First();

                sessionToUpdate.Capacity = newCapacity;
                return(db.SaveChanges() > 0);
            }

            else
            {
                Debug.WriteLine("Invalid session id.");
                return(false);
            }
        }
Esempio n. 5
0
        public bool UpdateSessionTime(TimeSpan startTime, TimeSpan endTime, int sessionId)
        {
            var matchingSessions = db.CourseSessions.Where(cs => cs.Id.Equals(sessionId));

            if (matchingSessions.Count() > 0)
            {
                CourseSession sessionToUpdate = matchingSessions.First();

                sessionToUpdate.StartTime = startTime;
                sessionToUpdate.EndTime   = endTime;
                return(db.SaveChanges() > 0);
            }

            else
            {
                Debug.WriteLine("Invalid session id.");
                return(false);
            }
        }
Esempio n. 6
0
        // Additional Data Access Functionality

        #region Register Student for Session
        public bool RegisterStudent(int studentId, int sessionId)
        {
            List <Schedule> allSchedules           = GetSchedules();
            var             currentStudentSchedule = allSchedules.Where(s => s.StudentId.Equals(studentId));

            List <CourseSession> allSessions = GetSessions();
            var           matchingSessions   = allSessions.Where(i => i.Id.Equals(sessionId));
            CourseSession session            = matchingSessions.First();

            //Check for time conflicts
            bool timeConflict;

            timeConflict = false;
            foreach (Schedule scheduleEntry in currentStudentSchedule)
            {
                if (scheduleEntry.CourseSession.DaysInSession == session.DaysInSession)
                {
                    if (
                        (scheduleEntry.CourseSession.StartTime == session.StartTime) ||
                        (scheduleEntry.CourseSession.StartTime > session.StartTime && scheduleEntry.CourseSession.StartTime < session.EndTime)
                        )
                    {
                        timeConflict = true;
                    }
                }
            }

            if (timeConflict)
            {
                Debug.WriteLine("Student is already registered for a class during this time.");
                return(false);
            }

            else
            {
                Schedule registrationEntry = new Schedule()
                {
                    StudentId = studentId, CourseSessionId = sessionId
                };
                return(InsertSchedule(registrationEntry));
            }
        }