예제 #1
0
        public IList <Score> GetScorebyStudentAndCourse(int studentId, int courseId)
        {
            var student = _userRepository.GetById(studentId);

            if (student == null || !UserServices.IsUserStudent(student))
            {
                return(new List <Score>());
            }



            var course        = _courseRepository.GetById(courseId);
            var componentList = course.Components;

            if (componentList == null)
            {
                return(new List <Score>());
            }

            var scoreList = new List <Score>();

            foreach (var component in componentList)
            {
                var score = _scoreRepository.GetByStudentIdAndComponentId((Student)student, component);
                if (score == null)
                {
                    var defaultScore = new Score()
                    {
                        Student   = (Student)student,
                        Component = component,
                        Value     = 0,
                    };
                    score = _scoreRepository.CreateOrUpdate(defaultScore);
                }
                scoreList.Add(score);
            }


            return(scoreList);
        }