Exemplo n.º 1
0
        private List <HometaskMark> GetHometasksMarksFromNode(XElement hometasksMarksNode)
        {
            List <HometaskMark> hometasksMarks = new List <HometaskMark>();

            foreach (var mark in hometasksMarksNode.Elements())
            {
                HometaskMark importMark = new HometaskMark
                {
                    Id             = Convert.ToInt32(mark.Attribute("id").Value),
                    ComplitionDate = mark.Attribute("complition-date").Value.GetDate(),
                    Done           = Convert.ToBoolean(mark.Attribute("done").Value)
                };
                hometasksMarks.Add(importMark);
            }

            return(hometasksMarks);
        }
Exemplo n.º 2
0
        private XElement GetMarkXmlPresentation(HometaskMark mark)
        {
            XElement markElement = new XElement("mark", new XAttribute("id", mark.Id),
                                                new XAttribute("complition-date", mark.ComplitionDate.GetDate()),
                                                new XAttribute("done", mark.Done)
                                                );

            XElement course = new XElement("course");

            course.Add(new XElement("course", new XAttribute("id", mark.Course.Id),
                                    new XAttribute("name", mark.Course.Name))
                       );

            XElement hometask = new XElement("hometask");

            hometask.Add(new XElement("hometask", new XAttribute("id", mark.Hometask.Id),
                                      new XAttribute("name", mark.Hometask.Name))
                         );

            markElement.Add(course);
            markElement.Add(hometask);

            return(markElement);
        }
Exemplo n.º 3
0
        private Academy GetAcademyObjectModelFromXml(XDocument document)
        {
            Academy  academy     = new Academy();
            XElement academyNode = document.Elements().First();

            XElement      coursesNode = academyNode.Descendants("courses-list").FirstOrDefault();
            List <Course> courses     = GetCoursesFromNode(coursesNode);

            XElement        lecturersNode = academyNode.Descendants("lecturers-list").FirstOrDefault();
            List <Lecturer> lecturers     = GetLecturersFromNode(lecturersNode);

            XElement       studentsNode = academyNode.Descendants("students-list").FirstOrDefault();
            List <Student> students     = GetStudentsFromNode(studentsNode);

            XElement        hometasksNode = academyNode.Descendants("hometasks-list").FirstOrDefault();
            List <Hometask> hometasks     = GetHometasksFromNode(hometasksNode);

            XElement            hometasksMarksNode = academyNode.Descendants("hometasks-marks-list").FirstOrDefault();
            List <HometaskMark> hometasksMarks     = GetHometasksMarksFromNode(hometasksMarksNode);

            List <KeyValuePair <int, int> > bindingCoursesLecturersDictionary = GetBindingDictionaryById(coursesNode, "lecturers");
            List <KeyValuePair <int, int> > bindingCoursesStudentsDictionary  = GetBindingDictionaryById(coursesNode, "students");
            List <KeyValuePair <int, int> > bindingCoursesHometasksDictionary = GetBindingDictionaryById(coursesNode, "hometasks");

            List <KeyValuePair <int, int> > bindingStudentsMarksDictionary  = GetBindingDictionaryById(studentsNode, "hometask-marks");
            List <KeyValuePair <int, int> > bindingMarksHometasksDictionary = GetBindingDictionaryById(hometasksMarksNode, "hometask");
            List <KeyValuePair <int, int> > bindingMarksCoursesDictionary   = GetBindingDictionaryById(hometasksMarksNode, "course");

            // courses and lecturers binding
            foreach (var courseLecturer in bindingCoursesLecturersDictionary)
            {
                Course   course   = courses.Where(n => n.Id == courseLecturer.Key).First();
                Lecturer lecturer = lecturers.Where(n => n.Id == courseLecturer.Value).First();

                course.Lecturers.Add(lecturer);
                lecturer.Courses.Add(course);
            }

            // courses and students binding
            foreach (var courseStudent in bindingCoursesStudentsDictionary)
            {
                Course  course  = courses.Where(n => n.Id == courseStudent.Key).First();
                Student student = students.Where(n => n.Id == courseStudent.Value).First();

                course.Students.Add(student);
                student.Courses.Add(course);
            }

            // courses and hometasks binding
            foreach (var courseHometask in bindingCoursesHometasksDictionary)
            {
                Course   course   = courses.Where(n => n.Id == courseHometask.Key).First();
                Hometask hometask = hometasks.Where(n => n.Id == courseHometask.Value).First();

                course.Hometasks.Add(hometask);
                hometask.Course = course;;
            }

            // staudents and marks binding
            foreach (var studentMark in bindingStudentsMarksDictionary)
            {
                Student      student = students.Where(n => n.Id == studentMark.Key).First();
                HometaskMark mark    = hometasksMarks.Where(n => n.Id == studentMark.Value).First();

                student.Marks.Add(mark);
            }

            // marks and hometasks binding
            foreach (var markHometask in bindingMarksHometasksDictionary)
            {
                HometaskMark mark     = hometasksMarks.Where(n => n.Id == markHometask.Key).First();
                Hometask     hometask = hometasks.Where(n => n.Id == markHometask.Value).First();

                mark.Hometask = hometask;
                hometask.HomeworkMarks.Add(mark);
            }

            // marks and courses binding
            foreach (var markHometask in bindingMarksCoursesDictionary)
            {
                HometaskMark mark   = hometasksMarks.Where(n => n.Id == markHometask.Key).First();
                Course       course = courses.Where(n => n.Id == markHometask.Value).First();

                mark.Course = course;
            }

            academy.Courses        = courses;
            academy.Lecturers      = lecturers;
            academy.Students       = students;
            academy.Hometasks      = hometasks;
            academy.HometasksMarks = hometasksMarks;

            return(academy);
        }