Exemplo n.º 1
0
        public TeacherTeacherSubjectDTOItems GetSubjectDTOListByTeacherId(string teacherId)
        {
            Teacher foundTeacher = db.TeachersRepository.GetByID(teacherId);

            if (foundTeacher == null)
            {
                throw new HttpException("Teacher with id: " + teacherId + " was not found");
            }

            IEnumerable <TeacherToSubject> teacherSubjects = foundTeacher.TeachersSubjects;

            TeacherTeacherSubjectDTOItems dto = new TeacherTeacherSubjectDTOItems
            {
                TeacherId = foundTeacher.Id,
                Teacher   = foundTeacher.LastName + " " + foundTeacher.FirstName,
                Subjects  = new List <TeacherSubjectDTOItemForTeacher>()
            };

            foreach (var ts in teacherSubjects)
            {
                TeacherSubjectDTOItemForTeacher subjectDTO = ConvertToTeacherSubjectDTOItemForTeacher(ts);
                dto.Subjects.Add(subjectDTO);
            }

            dto.Subjects = dto.Subjects.OrderBy(x => x.Subject).ToList();
            return(dto);
        }
Exemplo n.º 2
0
        private TeacherSubjectDTOItemForTeacher ConvertToTeacherSubjectDTOItemForTeacher(TeacherToSubject ts)
        {
            if (ts == null)
            {
                return(null);
            }

            TeacherSubjectDTOItemForTeacher dto = new TeacherSubjectDTOItemForTeacher
            {
                SubjectId       = ts.Subject.Id,
                Subject         = ts.Subject.Name,
                StartedTeaching = ts.StartedTeaching,
                StoppedTeaching = ts.StoppedTeaching
            };

            return(dto);
        }