public UnitOfWork(ENET_Project_Active_Learning_Group4Entities context)
        {
            _context = context;
            Users    = new UserRepository(_context);

            Courses = new CourseRepository();
        }
        public void AddStudentAccount(User user)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    db.Users.Add(user);
                    db.SaveChanges();

                    Student student = new Student();
                    foreach (var _user in db.Users)
                    {
                        if (_user.Username == user.Username)
                        {
                            student.Sid = _user.Sid;

                            db.Students.Add(student);

                            break;
                        }
                    }

                    db.SaveChanges();

                    scope.Complete();
                }
            }
        }
        public void AddInstructorAccount(User user)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    db.Users.Add(user);
                    db.SaveChanges();

                    Instructor instructor = new Instructor();
                    foreach (var _user in db.Users)
                    {
                        if (_user.Username == user.Username)
                        {
                            instructor.Sid = _user.Sid;

                            db.Instructors.Add(instructor);

                            break;
                        }
                    }
                    db.SaveChanges();

                    scope.Complete();
                }
            }
        }
        //public CourseRepository(ENET_Project_Active_Learning_Group4Entities context) : base(context)
        //{
        //}

        public void AddCourse(Course course)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                db.Courses.Add(course);
                db.SaveChanges();
            }
        }
        public void EnrolStudentToCourse(int courseID, int studentID)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                Student_Course_Map map = new Student_Course_Map();
                map.StudentSid = studentID;
                map.CourseSid  = courseID;

                db.Student_Course_Map.Add(map);
                db.SaveChanges();
            }
        }
        public void EnrolInstructorToCourse(int courseID, int instructorID)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                Instructor_Course_Map map = new Instructor_Course_Map();
                map.InstructorSid = instructorID;
                map.CourseSid     = courseID;

                db.Instructor_Course_Map.Add(map);
                db.SaveChanges();
            }
        }
        public bool IsCourseExist(int courseID)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                foreach (var _course in db.Courses)
                {
                    if (_course.Sid == courseID)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public List <Course> GetCoursesByStudent(int studentID)
        {
            List <Course> _courses = new List <Course>();

            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                foreach (var course in db.Student_Course_Map)
                {
                    if (course.StudentSid == studentID)
                    {
                        _courses.Add(course.Course);
                    }
                }
            }

            return(_courses);
        }
        public List <Course> GetCoursesByInstructor(int instructorID)
        {
            List <Course> _courses = new List <Course>();

            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                foreach (var course in db.Instructor_Course_Map)
                {
                    if (course.InstructorSid == instructorID)
                    {
                        _courses.Add(course.Course);
                    }
                }
            }

            return(_courses);
        }
        public void CheckAuthentication(User user)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                var _user = db.Users.SingleOrDefault(a => a.Username == user.Username && a.Password == user.Password);

                if (_user != null)
                {
                    if (db.Students.SingleOrDefault(a => a.Sid == _user.Sid) != null)
                    {
                        // Student exists
                    }
                    else if (db.Instructors.SingleOrDefault(a => a.Sid == _user.Sid) != null)
                    {
                        // Instructor exists
                    }
                }
            }
        }
        public void RemoveStudentFromCourse(int courseID, int studentID)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                Student_Course_Map map = null;;

                foreach (var course in db.Student_Course_Map)
                {
                    if (course.StudentSid == studentID && course.CourseSid == courseID)
                    {
                        map = course;

                        break;
                    }
                }

                if (map != null)
                {
                    db.Student_Course_Map.Remove(map);
                    db.SaveChanges();
                }
            }
        }
        public void RemoveInstructorFromCourse(int courseID, int instructorID)
        {
            using (ENET_Project_Active_Learning_Group4Entities db = new ENET_Project_Active_Learning_Group4Entities())
            {
                Instructor_Course_Map map = null;

                foreach (var course in db.Instructor_Course_Map)
                {
                    if (course.InstructorSid == instructorID && course.CourseSid == courseID)
                    {
                        map = course;

                        break;
                    }
                }

                if (map != null)
                {
                    db.Instructor_Course_Map.Remove(map);
                    db.SaveChanges();
                }
            }
        }
 public UserRepository(ENET_Project_Active_Learning_Group4Entities context) : base(context)
 {
 }