Beispiel #1
0
        public void AddStudentCourse(StudentCourseAdapter sc)
        {
            Student stud = GetStudent(sc.StudentId);

            if (stud == null)
            {
                throw new Exception("Student with the same id not found...");
            }

            Course course = GetCourse(sc.CourseId);

            if (course == null)
            {
                throw new Exception("Course with the same id not found...");
            }

            Func <StudentCourseAdapter, bool> predicat = item =>
            {
                bool b1 = item.StudentId == sc.StudentId && item.CourseId == sc.CourseId;
                bool b2 = item.RegisterYear == sc.RegisterYear && item.RegisterSemester == sc.RegisterSemester;
                return(b1 && b2);
            };


            if (studentCourseList.Any(predicat))
            {
                throw new Exception("can not Register the course in the same year and the same semester more than once...");
            }

            studentCourseList.Add(sc);
        }
Beispiel #2
0
        public void UpdateStudentCourse(StudentCourseAdapter sc)
        {
            Predicate <StudentCourseAdapter> predicat = item =>
            {
                bool b1 = item.StudentId == sc.StudentId && item.CourseId == sc.CourseId;
                bool b2 = item.RegisterYear == sc.RegisterYear && item.RegisterSemester == sc.RegisterSemester;
                return(b1 && b2);
            };

            XElement toUpdate = (from item in studentCourseRoot.Elements()
                                 let temp = ConvertStudentCourse(item)
                                            where predicat(temp)
                                            select item).FirstOrDefault();

            if (toUpdate == null)
            {
                throw new Exception("not found...");
            }
            foreach (PropertyInfo item in typeof(BE.StudentCourseAdapter).GetProperties())
            {
                toUpdate.Element(item.Name).SetValue(item.GetValue(sc));
            }

            studentCourseRoot.Save(studentCoursePath);
        }
        public void AddCourseToStudent(int studentId, int courseId, int year, Semester semester)
        {
            StudentCourseAdapter studentCourse = new StudentCourseAdapter
            {
                StudentId        = studentId,
                CourseId         = courseId,
                RegisterYear     = year,
                RegisterSemester = semester
            };

            dal.AddStudentCourse(studentCourse);
        }
Beispiel #4
0
        BE.StudentCourseAdapter ConvertStudentCourse(XElement element)
        {
            StudentCourseAdapter studentCourse = new StudentCourseAdapter();

            foreach (PropertyInfo item in typeof(BE.StudentCourseAdapter).GetProperties())
            {
                TypeConverter typeConverter = TypeDescriptor.GetConverter(item.PropertyType);
                object        convertValue  = typeConverter.ConvertFromString(element.Element(item.Name).Value);

                item.SetValue(studentCourse, convertValue);
            }

            return(studentCourse);
        }
Beispiel #5
0
        public void UpdateStudentCourse(StudentCourseAdapter sc)
        {
            Predicate <StudentCourseAdapter> predicat = item =>
            {
                bool b1 = item.StudentId == sc.StudentId && item.CourseId == sc.CourseId;
                bool b2 = item.RegisterYear == sc.RegisterYear && item.RegisterSemester == sc.RegisterSemester;
                return(b1 && b2);
            };

            int index = studentCourseList.FindIndex(predicat);

            if (index == -1)
            {
                throw new Exception("not found...");
            }

            studentCourseList[index] = sc;
        }
Beispiel #6
0
        public bool RemoveCourseFromStudent(int studentId, int courseId, int year, Semester semester)
        {
            Func <StudentCourseAdapter, bool> predicat = item =>
            {
                bool b1 = item.StudentId == studentId && item.CourseId == courseId;
                bool b2 = item.RegisterYear == year && item.RegisterSemester == semester;
                return(b1 && b2);
            };


            StudentCourseAdapter sc = studentCourseList.FirstOrDefault(predicat);

            if (sc == null)
            {
                throw new Exception("not found...");
            }

            return(studentCourseList.Remove(sc));
        }
        public void UpdateStudentCourseGrade(int studentId, int courseId, int year, Semester semester, float?grade)
        {
            if (grade > 100)
            {
                throw new Exception("The maximum grade is '100'");
            }
            if (grade < 0)
            {
                throw new Exception("The minimum grade is '0' (or null)");
            }

            StudentCourseAdapter studentCourse = new StudentCourseAdapter
            {
                StudentId        = studentId,
                CourseId         = courseId,
                RegisterYear     = year,
                RegisterSemester = semester,
                Grade            = grade
            };

            dal.UpdateStudentCourse(studentCourse);
        }