示例#1
0
        /// <summary>
        /// This function takes which ever values that are in the drop down list,
        /// Then tries to add the selected student into the selected course.
        /// </summary>
        public void addStudent()
        {
            //Get the course ID thats been selected.
            var selectedCourseID = selectedCourseList.courseID;

            using (RegistarDbContext db = new RegistarDbContext())
            {
                //Find the course in the database.
                var course = db.tblCourses.Where(c => c.courseID == selectedCourseID).FirstOrDefault();

                //Find the student to add from the database.
                var student = db.tblStudents.Where(s => s.studentID == selectedStudentList.studentID).FirstOrDefault();

                if (checkIfExists(course, student))
                {
                    MessageBox.Show("The student is already in the list!", "ERROR: ", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    //Add it to the coruses student list.
                    course.tblStudents.Add(student);
                    db.SaveChanges();
                    MessageBox.Show(String.Format("{0} was successfully enrolled in {1}!", student.fullName, course.name), "Student successfully added!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
示例#2
0
        /// <summary>
        /// This function removes the selected class from the database.
        /// </summary>
        public void RemoveClass()
        {
            //Get the course we want to remove.
            course = selectedCourseList;

            //Display message to confirm action.
            switch (MessageBox.Show(
                        String.Format("This will remove the course {0}. Are you sure you want to remove this course?", course.name),
                        "WARNING: Are you sure you want to remove the course?", MessageBoxButton.YesNo, MessageBoxImage.Question))
            {
            case MessageBoxResult.Yes:
                using (RegistarDbContext db = new RegistarDbContext())
                {
                    var classList = db.tblCourses
                                    .Where(id => id.courseID == course.courseID)
                                    .Select(c => c).FirstOrDefault();

                    db.tblCourses.Remove(classList);
                    db.SaveChanges();
                }
                break;

            case MessageBoxResult.No:
                break;
            }
        }
示例#3
0
        public void UpdateStudentCourses()
        {
            using (var dbInfo = new RegistarDbContext())
            {
                var stud = dbInfo.tblStudents.Where(b => b.userID == userinfo.userID).FirstOrDefault();
                if (selectedList == null)
                {
                    stud.tblCourses.Clear();
                    dbInfo.SaveChanges();
                    return;
                }

                var coursesFromSelListHS = new HashSet <int>(selectedList.Select(s => s.courseID));
                var coursesFromStudentDB = new HashSet <int>(stud.tblCourses.Select(c => c.courseID));


                foreach (var course in dbInfo.tblCourses)
                {
                    if (coursesFromSelListHS.Contains(course.courseID))
                    {
                        if (!coursesFromStudentDB.Contains(course.courseID))
                        {
                            stud.tblCourses.Add(course);
                            //stud.Courses.Add(course);
                        }
                    }
                    else
                    {
                        if (coursesFromStudentDB.Contains(course.courseID))
                        {
                            stud.tblCourses.Remove(course);
                        }
                    }
                }
                dbInfo.SaveChanges();
            }
        }
示例#4
0
        public void Save(tblCours newCourse)
        {
            using (RegistarDbContext db = new RegistarDbContext())
            {
                //Add new newest course ID to the course.
                if (newCourse.courseID == 0)
                {
                    newCourse.courseID = NewestCourseID;
                }


                db.tblCourses.Add(newCourse);
                db.SaveChanges();
            }
        }
示例#5
0
        public void saveTeacher()
        {
            using (RegistarDbContext db = new RegistarDbContext())
            {
                //Check if the tblUser already exists:
                if (Teacher.userID == 0)
                {
                    //Create the new user first:
                    //Get the newest userID
                    var userID = db.tblUsers.Select(u => u.userID).ToList();

                    var lastUserID = userID.Last();
                    lastUserID += 1;

                    //create a new holder.
                    Username = new tblUser {
                        userID = lastUserID, password = Password, userAccess = 1
                    };

                    //Try to incert into tblUser
                    db.tblUsers.Add(Username);

                    //add the missing value into Student.
                    Teacher.userID = lastUserID;
                }

                //Select the student table.
                var Teachers = db.tblTeachers;

                //Try to create the new student.
                Teachers.Add(Teacher);

                db.SaveChanges();
            }

            //This will update the teacher number so that the user can enter multiple new teachers.
            //((AdminViewModel)this.DataContext).GetLatestTeacher();

            //TODO: Update list in dropdown list.
            //((AdminViewModel)DataContext).selectedTeacherList = ((AdminViewModel)DataContext).getClasses();
        }
示例#6
0
        /// <summary>
        /// This function gets the student that you've selected in the class list,
        /// Then removes it.
        /// </summary>
        public void RemoveSelectedStudent()
        {
            //Get the course that we want to remove from.
            course = selectedCourseList;


            using (RegistarDbContext db = new RegistarDbContext())
            {
                //Get the class list.
                var classList = db.tblCourses.Where(c => c.courseID == course.courseID).FirstOrDefault();

                //Get the student infromation from the database.
                var studentToRemove = db.tblStudents.Where(s => s.studentID == selectedStudentsInClass.studentID).FirstOrDefault();

                //Remove the selected student.
                classList.tblStudents.Remove(studentToRemove);

                db.SaveChanges();
                MessageBox.Show(String.Format("{0} was removed successfully!", studentToRemove.fullName), "Student successfully removed", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
示例#7
0
        public void saveStudent()
        {
            using (RegistarDbContext db = new RegistarDbContext())
            {
                //Check if the tblUser already exists:
                if (Student.userID == 0)
                {
                    //Create the new user first:
                    //Get the newest userID
                    var userID = db.tblUsers.Select(u => u.userID).ToList();

                    var lastUserID = userID.Last();
                    lastUserID += 1;

                    //create a new holder.
                    Username = new tblUser {
                        userID = lastUserID, password = Password, userAccess = 0
                    };

                    //Try to incert into tblUser
                    db.tblUsers.Add(Username);

                    //add the missing value into Student.
                    Student.userID = lastUserID;
                }

                //Select the student table.
                var Students = db.tblStudents;

                //Try to create the new student.
                Students.Add(Student);

                db.SaveChanges();
            }

            //TODO: Update list in dropdown list.
            //((AdminViewModel)DataContext).selectedStudentList = ((AdminViewModel)DataContext).getStudentNames();
        }
示例#8
0
        /// <summary>
        /// This function prompts you with a messagebox that as if you want to remove all the students from the list,
        /// It then removes each student.
        /// </summary>
        public void DeleteAll()
        {
            //Get the course that we want to remove.
            course = selectedCourseList;

            //Display message to confirm action.
            switch (MessageBox.Show(
                        String.Format("This will remove all the students from {0}. Are you sure you want to perform this action?", course.name),
                        "WARNING: Are you sure you want to clear the class list?", MessageBoxButton.YesNo, MessageBoxImage.Warning))
            {
            case MessageBoxResult.Yes:
                using (RegistarDbContext db = new RegistarDbContext())
                {
                    //Select all the classes with the course ID.
                    var classList = db.tblCourses.Where(c => c.courseID == course.courseID).FirstOrDefault();

                    //Select all the students you want to delete.
                    var studentsInClass = db.tblCourses
                                          .Where(n => n.courseID == course.courseID)
                                          .SelectMany(s => s.tblStudents);

                    //For each of the students that we want to delete:
                    foreach (var item in studentsInClass)
                    {
                        //Remove it from the student list in the coresponding course list.
                        classList.tblStudents.Remove(item);
                    }
                    db.SaveChanges();
                    MessageBox.Show(String.Format("{0} was cleared successfully!", course.name), "Course successfully cleared", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;

            case MessageBoxResult.No:
                break;
            }
        }