示例#1
0
        public FileSaveSchedule ToFileSchedule()
        {
            var result = new FileSaveSchedule
            {
                auditoriums = new List<Auditorium>(),
                calendars = new List<FileSaveCalendar>(),
                disciplines = new List<WebDiscipline>(),
                lessons = new List<WebLesson>(),
                rings = new List<FileSaveRing>(),
                students = new List<WebStudent>(),
                studentGroups = new List<StudentGroup>(),
                studentsInGroups = new List<WebStudentsInGroups>(),
                teachers = new List<Teacher>(),
                teacherForDisciplines = new List<WebTeacherForDiscipline>(),

                configOptions = new List<ConfigOption>(),
                lessonLogEvents = new List<WebLessonLogEvent>()
            };

            foreach (var a in auditoriums)
            {
                result.auditoriums.Add(a);
            }

            foreach (var c in calendars)
            {
                result.calendars.Add(new FileSaveCalendar
                    {
                        CalendarId = c.CalendarId,
                        Date = c.Date.ToString("dd.MM.yyyy")
                    }
                );
            }

            foreach (var r in rings)
            {
                result.rings.Add(new FileSaveRing{RingId = r.RingId, Time = r.Time.ToString("H:mm")});
            }

            foreach (var sg in studentGroups)
            {
                result.studentGroups.Add(sg);
            }

            foreach (var t in teachers)
            {
                result.teachers.Add(t);
            }

            foreach (var co in configOptions)
            {
                result.configOptions.Add(co);
            }

            foreach (var d in disciplines)
            {
                var newD = new WebDiscipline {
                    Attestation = d.Attestation,
                    AuditoriumHours = d.AuditoriumHours,
                    DisciplineId = d.DisciplineId,
                    LectureHours = d.LectureHours,
                    Name = d.Name,
                    PracticalHours = d.PracticalHours,
                    StudentGroupId = d.StudentGroup.StudentGroupId
                };

                result.disciplines.Add(newD);
            }

            foreach (var s in students)
            {
                result.students.Add(new WebStudent {
                    StudentId = s.StudentId,
                    F = s.F,
                    I = s.I,
                    O = s.O,
                    Starosta = s.Starosta ? 1 : 0,
                    NFactor = s.NFactor ? 1 : 0,
                    Expelled = s.Expelled ? 1 : 0
                });
            }

            foreach (var sig in studentsInGroups)
            {
                var stig = new WebStudentsInGroups {
                    StudentsInGroupsId = sig.StudentsInGroupsId,
                    StudentId = sig.Student.StudentId,
                    StudentGroupId = sig.StudentGroup.StudentGroupId
                };
                result.studentsInGroups.Add(stig);
            }

            foreach (var tfd in teacherForDisciplines)
            {
                var tefd = new WebTeacherForDiscipline {
                    TeacherForDisciplineId = tfd.TeacherForDisciplineId,
                    TeacherId = tfd.Teacher.TeacherId,
                    DisciplineId = tfd.Discipline.DisciplineId
                };
                result.teacherForDisciplines.Add(tefd);
            }

            foreach (var lesson in lessons)
            {
                var l = new WebLesson {
                    AuditoriumId = lesson.Auditorium.AuditoriumId,
                    CalendarId = lesson.Calendar.CalendarId,
                    IsActive = lesson.IsActive ? 1 : 0,
                    LessonId = lesson.LessonId,
                    RingId = lesson.Ring.RingId,
                    TeacherForDisciplineId = lesson.TeacherForDiscipline.TeacherForDisciplineId
                };
                result.lessons.Add(l);
            }

            foreach (var logEvent in lessonLogEvents)
            {
                int newLessonId = -1, oldLessonId = -1;
                if (logEvent.NewLesson != null)
                {
                    newLessonId = logEvent.NewLesson.LessonId;
                }
                if (logEvent.OldLesson != null)
                {
                    oldLessonId = logEvent.OldLesson.LessonId;
                }

                var lle = new WebLessonLogEvent {
                    Comment = logEvent.Comment,
                    DateTime = logEvent.DateTime,
                    LessonLogEventId = logEvent.LessonLogEventId,
                    NewLessonId = newLessonId,
                    OldLessonId = oldLessonId
                };
                result.lessonLogEvents.Add(lle);
            }

            return result;
        }
        public FileSaveSchedule ToFileSchedule()
        {
            var result = new FileSaveSchedule
            {
                auditoriums           = new List <Auditorium>(),
                calendars             = new List <FileSaveCalendar>(),
                disciplines           = new List <WebDiscipline>(),
                lessons               = new List <WebLesson>(),
                rings                 = new List <FileSaveRing>(),
                students              = new List <WebStudent>(),
                studentGroups         = new List <StudentGroup>(),
                studentsInGroups      = new List <WebStudentsInGroups>(),
                teachers              = new List <Teacher>(),
                teacherForDisciplines = new List <WebTeacherForDiscipline>(),

                configOptions   = new List <ConfigOption>(),
                lessonLogEvents = new List <WebLessonLogEvent>()
            };

            foreach (var a in auditoriums)
            {
                result.auditoriums.Add(a);
            }

            foreach (var c in calendars)
            {
                result.calendars.Add(new FileSaveCalendar
                {
                    CalendarId = c.CalendarId,
                    Date       = c.Date.ToString("dd.MM.yyyy")
                }
                                     );
            }

            foreach (var r in rings)
            {
                result.rings.Add(new FileSaveRing {
                    RingId = r.RingId, Time = r.Time.ToString("H:mm")
                });
            }

            foreach (var sg in studentGroups)
            {
                result.studentGroups.Add(sg);
            }

            foreach (var t in teachers)
            {
                result.teachers.Add(t);
            }

            foreach (var co in configOptions)
            {
                result.configOptions.Add(co);
            }

            foreach (var d in disciplines)
            {
                var newD = new WebDiscipline {
                    Attestation     = d.Attestation,
                    AuditoriumHours = d.AuditoriumHours,
                    DisciplineId    = d.DisciplineId,
                    LectureHours    = d.LectureHours,
                    Name            = d.Name,
                    PracticalHours  = d.PracticalHours,
                    StudentGroupId  = d.StudentGroup.StudentGroupId
                };

                result.disciplines.Add(newD);
            }

            foreach (var s in students)
            {
                result.students.Add(new WebStudent {
                    StudentId = s.StudentId,
                    F         = s.F,
                    I         = s.I,
                    O         = s.O,
                    Starosta  = s.Starosta ? 1 : 0,
                    NFactor   = s.NFactor ? 1 : 0,
                    Expelled  = s.Expelled ? 1 : 0
                });
            }

            foreach (var sig in studentsInGroups)
            {
                var stig = new WebStudentsInGroups {
                    StudentsInGroupsId = sig.StudentsInGroupsId,
                    StudentId          = sig.Student.StudentId,
                    StudentGroupId     = sig.StudentGroup.StudentGroupId
                };
                result.studentsInGroups.Add(stig);
            }

            foreach (var tfd in teacherForDisciplines)
            {
                var tefd = new WebTeacherForDiscipline {
                    TeacherForDisciplineId = tfd.TeacherForDisciplineId,
                    TeacherId    = tfd.Teacher.TeacherId,
                    DisciplineId = tfd.Discipline.DisciplineId
                };
                result.teacherForDisciplines.Add(tefd);
            }

            foreach (var lesson in lessons)
            {
                var l = new WebLesson {
                    AuditoriumId           = lesson.Auditorium.AuditoriumId,
                    CalendarId             = lesson.Calendar.CalendarId,
                    IsActive               = lesson.IsActive ? 1 : 0,
                    LessonId               = lesson.LessonId,
                    RingId                 = lesson.Ring.RingId,
                    TeacherForDisciplineId = lesson.TeacherForDiscipline.TeacherForDisciplineId
                };
                result.lessons.Add(l);
            }

            foreach (var logEvent in lessonLogEvents)
            {
                int newLessonId = -1, oldLessonId = -1;
                if (logEvent.NewLesson != null)
                {
                    newLessonId = logEvent.NewLesson.LessonId;
                }
                if (logEvent.OldLesson != null)
                {
                    oldLessonId = logEvent.OldLesson.LessonId;
                }

                var lle = new WebLessonLogEvent {
                    Comment          = logEvent.Comment,
                    DateTime         = logEvent.DateTime,
                    LessonLogEventId = logEvent.LessonLogEventId,
                    NewLessonId      = newLessonId,
                    OldLessonId      = oldLessonId
                };
                result.lessonLogEvents.Add(lle);
            }

            return(result);
        }