예제 #1
0
        // ReSharper disable once UnusedMember.Global
        public IEnumerable <LessonResponse> Post(LessonGetAllRequest request)
        {
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

            Guard.IsTrue(eu => eu.IsNew == false, existingUser);

            var allLessons = LessonRepository.GetAllNonDeleted();
            var allAuthors = allLessons.DistinctBy(al => new { al.Provider, al.ProviderId }).Select(au => UserRepository.GetUserByProviderAndProviderId(au.Provider, au.ProviderId));

            return(allLessons
                   .Select(lesson => new { Grade = existingUser.IsStudent ? GradeRepository.GetGrade(lesson.Id, request.Provider, request.ProviderId) : new GradeModel(), Lesson = lesson })
                   .Select(x => new LessonResponse // TODO: Use Automapper
            {
                Id = x.Lesson.Id,
                BookTitle = x.Lesson.BookTitle,
                BookAmazonUrl = x.Lesson.BookAmazonUrl,
                TheHookYouTubeVideo = x.Lesson.TheHookYouTubeVideo,
                TheTwoVocabularyWordsYouTubeVideo = x.Lesson.TheTwoVocabularyWordsYouTubeVideo,
                EnunciationVideo1 = x.Lesson.EnunciationVideo1,
                EnunciationVideo2 = x.Lesson.EnunciationVideo2,
                MainIdea = x.Lesson.MainIdea,
                SupportingIdea = x.Lesson.SupportingIdea,
                StoryDetails = x.Lesson.StoryDetails,
                StoryQuestions = x.Lesson.StoryQuestions,
                ImportantSentencesForWordScramble = x.Lesson.ImportantSentencesForWordScramble,
                LessonAuthor = allAuthors.Single(aa => aa.Provider == x.Lesson.Provider && aa.ProviderId == x.Lesson.ProviderId),
                NumberOfEnrolledStudents = x.Lesson.NumberOfEnrolledStudents,
                GradeResponse = x.Grade == null ? new GradeResponse() : new GradeResponse {
                    IsGraded = true, Grade = x.Grade.Grade, Comments = x.Grade.Comments
                }
            }));
        }