Exemple #1
0
        // getStudentData accessible by UserTypes Administrator, Lecturer and Student
        public static Tuple <ObservableCollection <StudentAssessment>, StudentUnit> GetStudentData(Student s, Unit u)
        {
            ObservableCollection <StudentAssessment> performance = new ObservableCollection <StudentAssessment>(s.Performance.Where(e => (e.Assessment.unit.ID == u.ID)).ToList());
            StudentUnit attendance = s.Units.Find(e => (e.unit.ID == u.ID));

            return(new Tuple <ObservableCollection <StudentAssessment>, StudentUnit>(performance, attendance));
        }
Exemple #2
0
        public IActionResult Enroll(int unitId, int studentId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var unit = _repos.Units.Get(unitId);

            if (unit == null)
            {
                return(NotFound("unit not found."));
            }

            var student = _repos.Students.Get(studentId);

            if (student == null)
            {
                return(NotFound("No record of that student exists."));
            }

            StudentUnit studentUnit = new StudentUnit()
            {
                Student   = student,
                StudentId = student.Id,
                Unit      = unit,
                UnitId    = unit.Id
            };

            student.StudentUnits.Add(studentUnit);
            student = _repos.Students.Update(student);
            _repos.Commit();

            return(Ok("Unit registration successful!"));
        }
Exemple #3
0
        public IActionResult Enroll(int id)
        {
            int    account = this.GetAccountId();
            Course course  = _repos.Courses
                             .GetWith(id, "Units");

            Student student = _repos.Students
                              .GetWith(account, "Course");

            if (student.Course == null)
            {
                student.Course = course;
                student        = _repos.Students.Update(student);
            }
            else
            {
                StudentCourse studentCourse = new StudentCourse()
                {
                    CourseId  = course.Id,
                    StudentId = account,
                    Course    = course,
                    Student   = student
                };

                studentCourse = _repos.StudentCourses.Create(studentCourse);
            }

            foreach (var item in course.Units)
            {
                StudentUnit studentUnit = new StudentUnit()
                {
                    Student   = student,
                    StudentId = student.Id,
                    Unit      = item,
                    UnitId    = item.Id
                };

                _repos.StudentUnits.Create(studentUnit);
            }

            _repos.Commit();

            return(RedirectToActionPermanent("EnrollmentSuccess", course));
        }
Exemple #4
0
        private void btnAddAttendance_Click(object sender, RoutedEventArgs e)
        {
            if (lsvStudents.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a student to change the attendence for", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                return;
            }

            Student     student     = lsvStudents.SelectedItem as Student;
            var         info        = student.Units;
            StudentUnit studentUnit = null;

            if (_context == null)
            {
                if (info.Count == 1)
                {
                    studentUnit = info.Single();
                }
                else
                {
                    if (lsvInfo.SelectedIndex == -1)
                    {
                        MessageBox.Show("You must select a unit to add the attendance for", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                        return;
                    }
                    studentUnit = (lsvInfo.SelectedItem as StudentUnit);
                }
            }
            else
            {
                if (student == null)
                {
                    throw new Exception("Student from list is null after cast. This should not happen");
                }
                studentUnit = student.Units.Where(su => (su.unit.ID == _context.ID)).Single();
            }

            var attendLecture = MessageBox.Show("Did " + student.LastName + " " + student.FirstName + "attend the lecture?",
                                                "Lecture Attendance", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);

            if (attendLecture == MessageBoxResult.Cancel)
            {
                return;
            }

            var attendPractical = MessageBox.Show("Did " + student.LastName + " " + student.FirstName + "attend the practical?",
                                                  "Practical Attendance", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);

            if (attendPractical == MessageBoxResult.Cancel)
            {
                return;
            }

            bool didAttendLecture   = (attendLecture == MessageBoxResult.Yes);
            bool didAttendPractical = (attendPractical == MessageBoxResult.Yes);

            if (!_loggedIn.AddStudentAttendance(student, studentUnit.unit, didAttendLecture, didAttendPractical))
            {
                MessageBox.Show("An error occurred updating these details in the database", "Databse Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }