示例#1
0
        public static Exam ToMarksModel(this ioschools.DB.exam row)
        {
            var exam = new Exam();

            exam.maxMark  = row.maxMark;
            exam.id       = row.id;
            exam.name     = row.name;
            exam.date     = row.exam_date.ToString(Constants.DATETIME_SHORT_DATE);
            exam.subjects = row.exam_subjects.OrderBy(x => x.name).Select(x => new IdName(x.id, x.name)).ToArray();

            // gets student entries
            // sections = classes
            var sections = row.exam_classes.ToModel(row.year);

            foreach (var examSection in sections)
            {
                var section = new ExamSection();
                section.class_name = examSection.class_name;
                section.class_id   = examSection.class_id;
                foreach (var examMark in examSection.marks)
                {
                    var mark = new ExamMark();
                    mark.student = examMark.student;
                    foreach (var entry in exam.subjects)
                    {
                        var subject = entry;
                        var exist   = row.exam_marks
                                      .SingleOrDefault(x => x.studentid.ToString() == mark.student.id &&
                                                       x.exam_subjectid.ToString() == subject.id);
                        var newmark = new IdName();
                        if (exist != null)
                        {
                            // show x if student absent
                            if (exist.absent)
                            {
                                newmark = new IdName(exist.id, "x");
                            }
                            else
                            {
                                newmark = new IdName(exist.id, exist.mark);
                            }
                        }
                        mark.marks.Add(newmark);
                    }
                    section.marks.Add(mark);
                }
                section.marks = section.marks.OrderBy(x => x.student.name).ToList();
                exam.sections.Add(section);
            }

            return(exam);
        }
示例#2
0
        public static List <ExamMark> ToMarkModel(this IEnumerable <classes_students_allocated> rows)
        {
            var marks = new List <ExamMark>();

            foreach (var row in rows)
            {
                var mark = new ExamMark()
                {
                    student = new IdName(row.studentid, row.user.ToName())
                };
                marks.Add(mark);
            }
            return(marks);
        }