Exemplo n.º 1
0
        public UserSimpleViewDTO DeleteParent(string id)
        {
            Parent parent = db.ParentsRepository.Get(user => user.Id == id).FirstOrDefault();

            IEnumerable <Student> students = db.StudentsRepository.Get(s => s.Parent.Id == parent.Id);

            if (parent == null)
            {
                logger.Warn("Parent with id {0} not found.", id);
                return(null);
            }

            foreach (var item in students)
            {
                logger.Info("Removing child with id {0} from parents' children list. Parent id {1}", item.Id, id);
                item.Parent = null;
            }

            db.ParentsRepository.Delete(parent);
            db.Save();

            logger.Info("Parent with id {0} deleted.", id);
            UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(parent);

            return(retVal);
        }
Exemplo n.º 2
0
        public IEnumerable <StudentWithParentDTO> GetAllByTeacherSchoolSubjectIdAndTeacherId(int id, string teacherId)
        {
            TeacherSchoolSubject ts = db.TeacherSchoolSubjectSRepository.GetByID(id);
            var teacher             = db.TeachersRepository.GetByID(teacherId);

            if (teacher == null)
            {
                logger.Warn("No teacher with id {0} found.", teacherId);
                throw new KeyNotFoundException("Teacher with that id not found.");
            }

            if (ts == null)
            {
                logger.Error("That teacher + school subject combination is nonexistant, id : {0}. Throwing ArgumentException.", id);
                throw new ArgumentException("TeacherSchoolSubjectId is not correct.", new ArgumentException());
            }

            var students = db.StudentsRepository
                           .Get(s => s.SchoolClass.SchoolClassTeacherSchoolSubjects.Any(x => x.TeacherSchoolSubject.Id == id &&
                                                                                        x.TeacherSchoolSubject.Teacher.Id == teacherId));

            logger.Info("Getting students taught by {0} {1}, subject: {2}. TeacherSchoolSubjectId : {3}",
                        ts.Teacher.FirstName, ts.Teacher.LastName, ts.SchoolSubject.Name, id);

            return(students
                   .Select(s => UserToUserDTOConverters.StudentToStudentWithParentDTO(s)));
        }
Exemplo n.º 3
0
        public UserSimpleViewDTO DeleteAdmin(string id)
        {
            Admin admin = db.AdminsRepository.Get(user => user.Id == id).FirstOrDefault();

            int adminCount = db.AdminsRepository.Get().Count();

            if (admin == null)
            {
                logger.Warn("Admin with id {0} not found.");
                return(null);
            }

            if (adminCount < 2)
            {
                logger.Warn("Less than 2 admins present in the system. Can't delete the last one!");
                return(null);
            }

            db.AdminsRepository.Delete(admin);
            db.Save();
            logger.Info("Deleting admin with id {0}", id);
            UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(admin);

            return(retVal);
        }
Exemplo n.º 4
0
        public IEnumerable <StudentWithParentDTO> GetAllByGradeDatesAndTeacherId(DateTime minValue, DateTime maxValue, string teacherId)
        {
            if (minValue < DateTime.MinValue || maxValue > DateTime.MaxValue || minValue > maxValue)
            {
                logger.Error("Date range incorrect. Date from: {0}, date to: {1}. Throwing DatesRangeException.", minValue, maxValue);
                throw new DatesRangeException();
            }

            var teacher = db.TeachersRepository.GetByID(teacherId);

            if (teacher == null)
            {
                logger.Warn("Getting teacher with id {0} failed. No such teacher", teacherId);
                throw new ArgumentException("No teacher with that id!");
            }

            var students = db.StudentsRepository
                           .Get(s => s.Grades.Any(grade => grade.DateOfGrading >= minValue && grade.DateOfGrading <= maxValue) &&
                                s.SchoolClass.SchoolClassTeacherSchoolSubjects.Any(x => x.TeacherSchoolSubject.Teacher.Id == teacherId));

            logger.Info("Getting students graded between {0} and {1} by teacher with id {2}.", minValue, maxValue, teacherId);

            var retVal = students.Select(
                s => UserToUserDTOConverters.StudentToStudentWithParentDTO(s)
                );

            return(retVal);
        }
Exemplo n.º 5
0
        public async Task <IdentityResult> RegisterTeacher(RegisterUserDTO user)
        {
            Teacher userToInsert = UserToUserDTOConverters.RegisterUserDTOtoTeacher(user);

            logger.Info("Registering teacher.");
            return(await db.AuthRepository.RegisterTeacher(userToInsert, user.Password));
        }
Exemplo n.º 6
0
        public async Task <IdentityResult> RegisterAdmin(RegisterUserDTO user)
        {
            Admin userToInsert = UserToUserDTOConverters.RegisterUserDTOtoAdmin(user);

            logger.Info("Registering admin.");
            return(await db.AuthRepository.RegisterAdmin(userToInsert, user.Password));
        }
Exemplo n.º 7
0
        public IEnumerable <StudentWithParentDTO> GetAllByStudentNameAndTeacherID(string name, string teacherId)
        {
            if (name == null)
            {
                throw new NullReferenceException();
            }

            var students = db.StudentsRepository.Get().Where(x => (x.FirstName + " " + x.LastName).ToLower().Contains(name.ToLower()));
            var teacher  = db.TeachersRepository.GetByID(teacherId);

            if (students == null)
            {
                logger.Warn("No students' name or surname contain the given string parameter \"{0}\"", name);
                throw new KeyNotFoundException("student with that string in their name or surname not found.");
            }

            if (teacher == null)
            {
                logger.Warn("No teacher with id {0} found.", teacherId);
                throw new KeyNotFoundException("Teacher with that id not found.");
            }

            var retVal = students.Where(x => x.SchoolClass.SchoolClassTeacherSchoolSubjects.Any(y => y.TeacherSchoolSubject.Teacher.Id == teacherId));

            logger.Info("Getting all students whose name or surname contain \"{0}\", and who have teacher id {1}", name, teacherId);

            return(retVal
                   .Select(s => UserToUserDTOConverters.StudentToStudentWithParentDTO(s)));
        }
Exemplo n.º 8
0
        public async Task <IdentityResult> RegisterStudent(RegisterStudentDTO user)
        {
            Student userToInsert = UserToUserDTOConverters.RegisterStudentDTOtoStudent(user);

            logger.Info("Registering student.");
            return(await db.AuthRepository.RegisterStudent(userToInsert, user.Password));
        }
Exemplo n.º 9
0
        public IEnumerable <StudentWithParentDTO> GetAllBySchoolClassIdAndTeacherId(int classId, string teacherId)
        {
            var schoolClass = db.SchoolClassesRepository.GetByID(classId);
            var teacher     = db.TeachersRepository.GetByID(teacherId);

            if (schoolClass == null)
            {
                logger.Error("SchoolClassId {0} doesn't exist.", classId);
                throw new KeyNotFoundException("That SchoolClassId doesn't exist. Throwing KeyNotFoundException.");
            }

            if (teacher == null)
            {
                logger.Error("TeacherID {0} doesn't exist.", teacherId);
                throw new KeyNotFoundException("That TeacherId doesn't exist. Throwing KeyNotFoundException.");
            }

            var students = db.StudentsRepository
                           .Get(s => s.SchoolClass.Id == classId &&
                                s.SchoolClass.SchoolClassTeacherSchoolSubjects
                                .Any(x => x.TeacherSchoolSubject.Teacher.Id == teacherId));

            logger.Info("Getting all students from class with id {0}, taught by teacher with ID {1}", classId, teacherId);

            return(students
                   .Select(s => UserToUserDTOConverters.StudentToStudentWithParentDTO(s)));
        }
Exemplo n.º 10
0
        public IEnumerable <StudentWithParentDTO> GetAllBySchoolSubjectIdAndTeacherId(int subjectId, string teacherId)
        {
            var schoolSubject = db.SchoolSubjectsRepository.GetByID(subjectId);
            var teacher       = db.TeachersRepository.GetByID(teacherId);

            if (schoolSubject == null)
            {
                logger.Error("SchoolSubjectId {0} doesn't exist. Throwing KeyNotFoundException.", subjectId);
                throw new KeyNotFoundException("That SchoolSubjectId doesn't exist.");
            }

            if (teacher == null)
            {
                logger.Warn("No teacher with id {0} found.", teacherId);
                throw new KeyNotFoundException("Teacher with that id not found.");
            }

            var students = db.StudentsRepository
                           .Get(s => s.SchoolClass.SchoolClassTeacherSchoolSubjects
                                .Any(x => x.TeacherSchoolSubject.SchoolSubject.Id == subjectId &&
                                     x.TeacherSchoolSubject.Teacher.Id == teacherId));

            logger.Info("Getting all students who have school subject with id {0} and who are taught by teacher with id {1}.", subjectId, teacherId);

            return(students
                   .Select(s => UserToUserDTOConverters.StudentToStudentWithParentDTO(s)));
        }
Exemplo n.º 11
0
        public IEnumerable <TeacherBasicDTO> GetAll()
        {
            var retVal = db.TeachersRepository.Get();

            logger.Info("Getting all teachers.");
            return(retVal.Select(x => UserToUserDTOConverters.TeacherToTeacherBasicDTO(x)));
        }
Exemplo n.º 12
0
        public TeacherBasicDTO GetById(string id)
        {
            var retVal = db.TeachersRepository.GetByID(id);

            logger.Info("Getting teacher with id {0}", id);
            return(UserToUserDTOConverters.TeacherToTeacherBasicDTO(retVal));
        }
Exemplo n.º 13
0
        public async Task <IEnumerable <UserViewWithRoleIdsDTO> > GetAllUsers()
        {
            IEnumerable <ApplicationUser> users = await db.AuthRepository.GetAllUsers();

            IEnumerable <UserViewWithRoleIdsDTO> retVal = users.Select(x => UserToUserDTOConverters.UserToUserViewWithRoleIds(x));

            return(retVal);
        }
Exemplo n.º 14
0
        public IEnumerable <StudentWithParentDTO> GetAll()
        {
            var students = db.StudentsRepository.Get();

            logger.Info("Getting all entries of type {0}.", students.GetType());

            return(students.Select(x => UserToUserDTOConverters.StudentToStudentWithParentDTO(x)));
        }
Exemplo n.º 15
0
        public IEnumerable <TeacherBasicDTO> GetAllTeachingToStudent(string id)
        {
            var retVal = db.TeachersRepository.Get()
                         .Where(x => x.TeacherSchoolSubjects.Any(y => y.SchoolClassTeacherSchoolSubjects.Any(z => z.SchoolClass.Students.Any(a => a.Id == id))));

            logger.Info("Getting all teachers teaching to student with id {0}.", id);
            return(retVal.Select(x => UserToUserDTOConverters.TeacherToTeacherBasicDTO(x)));
        }
        public IEnumerable <ParentSimpleViewDTO> GetAll()
        {
            var parents = db.ParentsRepository.Get();

            logger.Info("Getting all entries of type {0}", parents.GetType());

            return(parents
                   .Select(x => UserToUserDTOConverters.ParentToParentSimpleViewDTO(x)));
        }
Exemplo n.º 17
0
        public IEnumerable <UserSimpleViewDTO> GetAllAdmins()
        {
            IEnumerable <ApplicationUser> users = db.AdminsRepository.Get();

            logger.Info("Getting all admins.");

            IEnumerable <UserSimpleViewDTO> retVal = users.Select(x => UserToUserDTOConverters.UserToUserSimpleViewDTO(x));

            return(retVal);
        }
Exemplo n.º 18
0
        public IEnumerable <ParentSimpleViewDTO> GetAllParents()
        {
            IEnumerable <Parent> users = db.ParentsRepository.Get();

            logger.Info("Getting all parents.");

            IEnumerable <ParentSimpleViewDTO> retVal = users.Select(x => UserToUserDTOConverters.ParentToParentSimpleViewDTO(x));

            return(retVal);
        }
Exemplo n.º 19
0
        public IEnumerable <StudentWithParentDTO> GetAllStudents()
        {
            IEnumerable <Student> users = db.StudentsRepository.Get();

            logger.Info("Getting all students.");

            IEnumerable <StudentWithParentDTO> retVal = users.Select(x => UserToUserDTOConverters.StudentToStudentWithParentDTO(x));

            return(retVal);
        }
Exemplo n.º 20
0
        public StudentWithParentGradesClassDTO GetById(string id)
        {
            Student student = db.StudentsRepository.GetByID(id);

            if (student == null || !(student is Student))
            {
                logger.Error("Student with id {0} not found, or of a wrong user type. Throwing KeyNotFoundException.", id);
                throw new KeyNotFoundException();
            }

            logger.Info("Getting student with id {0}", id);
            return(UserToUserDTOConverters.StudentToStudentWithParentGradesClassDTO(student));
        }
        public ParentSimpleViewDTO GetById(string id)
        {
            Parent parent = db.ParentsRepository.GetByID(id);

            logger.Info("Getting parent with id {0}.", id);

            if (parent == null || !(parent is Parent))
            {
                logger.Error("Parent with id {0} does not exist. Throwing key not found exception.", id);
                throw new KeyNotFoundException();
            }

            return(UserToUserDTOConverters.ParentToParentSimpleViewDTO(parent));
        }
Exemplo n.º 22
0
        public IEnumerable <TeacherBasicDTO> GetAllTeachingToAGrade(int grade)
        {
            var retVal = db.TeachersRepository.Get()
                         .Where(x => x.TeacherSchoolSubjects.Any(y => y.SchoolClassTeacherSchoolSubjects.Any(z => z.SchoolClass.SchoolGrade == grade)));

            if (retVal == null)
            {
                logger.Error("No teachers assinged to {0} grade.", grade);
                throw new ArgumentException("No teachers teach to that grade.");
            }

            logger.Info("Getting teachers teaching to {0}th grade.", grade);
            return(retVal.Select(x => UserToUserDTOConverters.TeacherToTeacherBasicDTO(x)));
        }
Exemplo n.º 23
0
        public IEnumerable <TeacherBasicDTO> GetAllTeachingToClass(int id)
        {
            var retVal = db.TeachersRepository.Get()
                         .Where(x => x.TeacherSchoolSubjects.Any(y => y.SchoolClassTeacherSchoolSubjects.Any(z => z.SchoolClass.Id == id)));

            if (retVal == null)
            {
                logger.Error("Class with id {0} is non existant.", id);
                throw new ArgumentException("No class with that id.");
            }

            logger.Info("Getting teachers teaching to a class with id {0}", id);
            return(retVal.Select(x => UserToUserDTOConverters.TeacherToTeacherBasicDTO(x)));
        }
Exemplo n.º 24
0
        public async Task <UserViewWithRoleIdsDTO> GetUserById(string id)
        {
            ApplicationUser user = await db.AuthRepository.FindUserById(id);

            if (user == null)
            {
                logger.Warn("No such user. {0}", id);
                return(null);
            }
            logger.Info("Getting user with id {0}", id);

            UserViewWithRoleIdsDTO retVal = UserToUserDTOConverters.UserToUserViewWithRoleIds(user);

            return(retVal);
        }
Exemplo n.º 25
0
        public UserSimpleViewDTO GetAdminById(string id)
        {
            Admin admin = db.AdminsRepository.Get(user => user.Id == id).FirstOrDefault();

            if (admin == null)
            {
                logger.Warn("No such admin. {0}", id);

                return(null);
            }
            logger.Info("Getting admin with id {0}", id);
            UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(admin);

            return(retVal);
        }
Exemplo n.º 26
0
        public UserSimpleViewDTO GetTeacherById(string id)
        {
            Teacher teacher = db.TeachersRepository.Get(user => user.Id == id).FirstOrDefault();

            if (teacher == null)
            {
                logger.Warn("No such teacher. {0}", id);
                return(null);
            }
            logger.Info("Getting teacher with id {0}", id);

            UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(teacher);

            return(retVal);
        }
Exemplo n.º 27
0
        public ParentSimpleViewDTO GetParentById(string id)
        {
            Parent parent = db.ParentsRepository.Get(p => p.Id == id).FirstOrDefault();

            if (parent == null)
            {
                logger.Warn("No such parent. {0}", id);
                return(null);
            }
            logger.Info("Getting parent with id {0}", id);

            ParentSimpleViewDTO retVal = UserToUserDTOConverters.ParentToParentSimpleViewDTO(parent);

            return(retVal);
        }
Exemplo n.º 28
0
        public StudentWithParentDTO GetStudentById(string id)
        {
            Student student = db.StudentsRepository.Get(s => s.Id == id).FirstOrDefault();

            if (student == null)
            {
                logger.Warn("No such student. {0}", id);

                return(null);
            }
            logger.Info("Getting student with id {0}", id);

            StudentWithParentDTO retVal = UserToUserDTOConverters.StudentToStudentWithParentDTO(student);

            return(retVal);
        }
Exemplo n.º 29
0
        public IEnumerable <StudentWithParentDTO> GetAllBySchoolClassGrade(int grade)
        {
            //TODO 11.2 **DONE** exception if grade not between 1-8
            if (grade < 1 || grade > 8)
            {
                logger.Error("Grade parameter value ({0}) incorrect. Must be in range 1-8. Throwing ArgumentOutOfRangeException.", grade);
                throw new ArgumentOutOfRangeException("Grade must be between 1 and 8!", new ArgumentOutOfRangeException());
            }

            var students = db.StudentsRepository
                           .Get(s => s.SchoolClass.SchoolGrade == grade);

            logger.Info("Getting students in grade: {0}.", grade);

            return(students
                   .Select(s => UserToUserDTOConverters.StudentToStudentWithParentDTO(s)));
        }
Exemplo n.º 30
0
        public UserSimpleViewDTO DeleteStudent(string id)
        {
            Student student = db.StudentsRepository.Get(user => user.Id == id).FirstOrDefault();

            if (student == null)
            {
                logger.Warn("Student with id {0} not found.", id);
                return(null);
            }

            db.StudentsRepository.Delete(student);
            db.Save();
            logger.Info("Student with id {0} deleted.", id);
            UserSimpleViewDTO retVal = UserToUserDTOConverters.UserToUserSimpleViewDTO(student);

            return(retVal);
        }