Beispiel #1
0
        public FormIdStudentsDTO GetSortedStudentsNamesByFormIdForParent(int formId, string parentId)
        {
            Parent foundParent = db.ParentsRepository.GetByID(parentId);

            if (foundParent == null)
            {
                //sanse da ulogovani korisnik ne postoji su nepostojece :)
                throw new HttpException("The User with id: " + parentId + " was not found.");
            }

            Form found = GetByID(formId);

            if (found == null)
            {
                throw new HttpException("The Form with id: " + formId + " was not found.");
            }

            IEnumerable <Student> students = found.Students;

            if (students.Count() == 0)
            {
                throw new HttpException("Student list is empty.");
            }
            if (students.Any(x => x.Parent.Id == parentId) == false)
            {
                throw new HttpException("Access Denied. We’re sorry, but you are not authorized to perform the requested operation.");
            }

            FormIdStudentsDTO dto = new FormIdStudentsDTO
            {
                Id               = found.Id,
                Grade            = found.Grade,
                Tag              = found.Tag,
                Started          = found.Started,
                AttendingTeacher = found.AttendingTeacher.FirstName + " " + found.AttendingTeacher.LastName,
                NumberOfStudents = 0,
                Students         = new List <FormStudentDTO>()
            };

            foreach (var student in students)
            {
                FormStudentDTO studentDTO = ConvertToFormStudentDTO(student);
                dto.Students.Add(studentDTO);
                dto.NumberOfStudents++;
            }

            dto.Students = dto.Students.OrderBy(x => x.Student).ThenBy(x => x.Id).ToList();
            return(dto);
        }
Beispiel #2
0
        private FormStudentDTO ConvertToFormStudentDTO(Student student)
        {
            if (student == null)
            {
                return(null);
            }

            FormStudentDTO dto = new FormStudentDTO
            {
                Id      = student.Id,
                Student = student.LastName + " " + student.FirstName
            };

            return(dto);
        }
Beispiel #3
0
        public IEnumerable <FormStudentDTO> GetStudentsByLastNameSorted(string lastName)
        {
            IEnumerable <Student> studentsByLastName = db.StudentsRepository.GetAllByLastName(lastName);

            IList <FormStudentDTO> dtos = new List <FormStudentDTO>();

            foreach (var student in studentsByLastName)
            {
                FormStudentDTO dto = ConvertToFormStudentDTO(student);
                dtos.Add(dto);
            }

            dtos = dtos.OrderBy(x => x.Student).ThenBy(x => x.Id).ToList();
            return(dtos);
        }
Beispiel #4
0
        public FormIdStudentsDTO GetSortedStudentsNamesByFormId(int id)
        {
            Form found = GetByID(id);

            if (found == null)
            {
                throw new HttpException("The Form with id: " + id + " was not found.");
            }

            IEnumerable <Student> students = found.Students;

            if (students.Count() == 0)
            {
                throw new HttpException("Student list is empty.");
            }

            FormIdStudentsDTO dto = new FormIdStudentsDTO
            {
                Id               = found.Id,
                Grade            = found.Grade,
                Tag              = found.Tag,
                Started          = found.Started,
                AttendingTeacher = found.AttendingTeacher.FirstName + " " + found.AttendingTeacher.LastName,
                NumberOfStudents = 0,
                Students         = new List <FormStudentDTO>()
            };

            foreach (var student in students)
            {
                FormStudentDTO studentDTO = ConvertToFormStudentDTO(student);
                dto.Students.Add(studentDTO);
                dto.NumberOfStudents++;
            }

            dto.Students = dto.Students.OrderBy(x => x.Student).ThenBy(x => x.Id).ToList();
            return(dto);
        }