Пример #1
0
        /// <summary>
        /// Retrieve all grades for a given course
        /// </summary>
        /// <returns></returns>
        public IEnumerable <GradeDto> GetGradesByCourses()
        {
            // NOTE misleading title. no grouping at all
            var grades = db.GradesRepository.Get()
                         .Select(g => GradesConverter.GradeToGradeDto(g));

            return(grades);
        }
Пример #2
0
        /// <summary>
        /// Retrieve all grades for a given student
        /// </summary>
        /// <param name="studentId"></param>
        /// <returns></returns>
        public IEnumerable <GradeDto> GetAllGradesForStudent(int studentId)
        {
            var grades = db.GradesRepository.Get(
                filter: g => g.Taking.StudentId == studentId)
                         .Select(g => GradesConverter.GradeToGradeDto(g));

            return(grades);
        }
Пример #3
0
        /// <summary>
        /// Retrieve all grades in the system
        /// </summary>
        /// <returns></returns>
        public IEnumerable <GradeDto> GetAllGrades()
        {
            // This is the most basic implementation, with every grade included, no ordering, no grouping..
            var grades = db.GradesRepository.Get()
                         .Select(g => GradesConverter.GradeToGradeDto(g));

            return(grades);
        }
Пример #4
0
        /// <summary>
        /// Retrieve all grades assigned by the given teacher
        /// </summary>
        /// <param name="teacherId"></param>
        /// <returns></returns>
        public IEnumerable <GradeDto> GetAllGradesForTeacher(int teacherId)
        {
            // Probably need to check the teacher...

            var grades = db.GradesRepository.Get(
                filter: g => g.Taking.Program.Teaching.TeacherId == teacherId)
                         .Select(g => GradesConverter.GradeToGradeDto(g));

            return(grades);
        }
Пример #5
0
        /// <summary>
        /// Retrieve all grades for a given parent
        /// It will call and retrieve grades for parent's children
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public IEnumerable <GradeDto> GetAllGradesForParent(int parentId)
        {
            var children    = db.ParentsRepository.GetByID(parentId).StudentParents.Select(sp => sp.Student);
            var childrenIds = new List <int>();

            foreach (var c in children)
            {
                childrenIds.Add(c.Id);
            }

            // Hmm... i'm not quite it will work...
            var grades = db.GradesRepository.Get(g => g.Taking.Student.StudentParents.Any(p => p.Parent.Id == parentId))
                         .Select(g => GradesConverter.GradeToGradeDto(g));

            return(grades);
        }
Пример #6
0
        public GradeDto UpdateGrade(GradeDto gradeDto)
        {
            Grade grade = GetGradeById(gradeDto.GradeId);

            if (grade == null)
            {
                return(null);
            }

            grade.Assigned   = gradeDto.AssignmentDate;
            grade.GradePoint = gradeDto.GradePoint;
            grade.Notes      = gradeDto.Notes;
            grade.SchoolTerm = gradeDto.Semester;

            db.GradesRepository.Update(grade);
            db.Save();

            return(GradesConverter.GradeToGradeDto(grade));
        }
Пример #7
0
        /// <summary>
        /// Retrieve grades by multiple parameters.
        /// Specialized methods can call this method.
        /// If the output format needs to be changed, we can supply a converter delegate, maybe?
        /// </summary>
        /// <param name="studentId"></param>
        /// <param name="gradeId"></param>
        /// <param name="teacherId"></param>
        /// <param name="courseId"></param>
        /// <param name="semesterId"></param>
        /// <param name="classId"></param>
        /// <returns></returns>
        public IEnumerable <GradeDto> GetGradesByParameters(
            int?gradeId       = null,
            int?courseId      = null,
            int?teacherId     = null,
            int?classRoomId   = null,
            int?studentId     = null,
            int?parentId      = null,
            int?semester      = null,
            int?schoolGrade   = null,
            int?grade         = null,
            DateTime?fromDate = null,
            DateTime?toDate   = null)
        {
            //Func<Grade, bool> filter =
            //    g => studentId != null ? g.Taking.StudentId == studentId : true &&
            //        gradeId != null ? g.Taking.Program.ClassRoom.ClassGrade == gradeId : true &&
            //        teacherId != null ? g.Taking.Program.Teaching.TeacherId == teacherId : true &&
            //        courseId != null ? g.Taking.Program.CourseId == courseId : true &&
            //        semesterId != null ? g.SchoolTerm == semesterId : true &&
            //        classId != null ? g.Taking.Program.ClassRoomId == classId : true;

            return(db.GradesRepository.Get(
                       filter:
                       g => (gradeId != null ? g.Id == gradeId : true) &&
                       (courseId != null ? g.Taking.Program.CourseId == courseId : true) &&
                       (teacherId != null ? g.Taking.Program.Teaching.TeacherId == teacherId : true) &&
                       (classRoomId != null ? g.Taking.Program.ClassRoomId == classRoomId : true) &&
                       (studentId != null ? g.Taking.StudentId == studentId : true) &&
                       (parentId != null ? g.Taking.Student.StudentParents.Any(sp => sp.ParentId == parentId) : true) &&
                       (semester != null ? g.SchoolTerm == semester : true) &&
                       (schoolGrade != null ? g.Taking.Program.ClassRoom.ClassGrade == schoolGrade : true) &&
                       (grade != null ? g.GradePoint == grade : true) &&
                       (fromDate != null ? g.Assigned >= fromDate : true) &&
                       (toDate != null ? g.Assigned <= toDate : true))
                   .Select(g => GradesConverter.GradeToGradeDto(g)));
        }