Exemple #1
0
        public static void Import(string path, ClassRepository classRepository, LessonRepository lessonRepository, ScheduleRepository scheduleRepository, TeacherRepository teacherRepository)
        {
            List <Lesson>   lessons   = null;
            List <Teacher>  teachers  = null;
            List <Class>    classes   = null;
            List <Schedule> schedules = null;

            IWorkbook workbook = null;

            var fs = File.OpenRead(path);

            if (path.IndexOf(".xlsx") > 0) // 2007版本
            {
                workbook = new XSSFWorkbook(fs);
            }
            else if (path.IndexOf(".xls") > 0) // 2003版本
            {
                workbook = new HSSFWorkbook(fs);
            }

            var courses = GetCourses(workbook.GetSheet("科目"));

            // TODO: 导入Lesson
            lessons = GetLessons(workbook.GetSheet("课程表"));

            // TODO: 导入Class
            teachers = new List <Teacher>();
            classes  = GetClasses(workbook.GetSheet("班级"), courses, teachers);

            // TODO: 导入Schedule
            schedules = new List <Schedule>();

            lessons.ForEach(lesson =>
            {
                lessonRepository.Add(lesson);
            });

            teachers.ForEach(teacher =>
            {
                teacherRepository.Add(teacher);
            });

            classes.ForEach(@class =>
            {
                classRepository.Add(@class);
            });

            schedules.ForEach(schedule =>
            {
                scheduleRepository.Add(schedule);
            });
        }
Exemple #2
0
        // ReSharper disable once UnusedMember.Global
        public LessonResponse Post(LessonUpsertRequest request)
        {
            Guard.AgainstEmpty(request.Provider);
            Guard.AgainstEmpty(request.ProviderId);
            var existingUser = UserHelpers.GetExistingUser(request, UserRepository);

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

            var lesson = new Lesson
            {
                Id                  = request.Id,
                BookTitle           = request.BookTitle,
                BookAmazonUrl       = request.BookAmazonUrl,
                TheHookYouTubeVideo = request.TheHookYouTubeVideo,
                TheTwoVocabularyWordsYouTubeVideo = request.TheTwoVocabularyWordsYouTubeVideo,
                EnunciationVideo1 = request.EnunciationVideo1,
                EnunciationVideo2 = request.EnunciationVideo2,
                MainIdea          = request.MainIdea,
                SupportingIdea    = request.SupportingIdea,
                StoryDetails      = request.StoryDetails,
                StoryQuestions    = request.StoryQuestions,
                ImportantSentencesForWordScramble = request.ImportantSentencesForWordScramble,
                Provider   = request.Provider,
                ProviderId = request.ProviderId
            };

            if (lesson.IsNew)
            {
                LessonRepository.Add(lesson);
            }
            else
            {
                if (request.Provider != lesson.Provider || request.ProviderId != lesson.ProviderId)
                {
                    throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized");
                }

                if (lesson.IsDeleted)
                {
                    throw new HttpError(HttpStatusCode.NotFound, "NotFound");
                }

                lesson.UpdateDateUtc = DateTime.UtcNow;
                LessonRepository.Update(lesson);
            }

            // TODO: Use Automapper
            return(new LessonResponse
            {
                Id = lesson.Id,
                BookTitle = lesson.BookTitle,
                BookAmazonUrl = lesson.BookAmazonUrl,
                TheHookYouTubeVideo = lesson.TheHookYouTubeVideo,
                TheTwoVocabularyWordsYouTubeVideo = lesson.TheTwoVocabularyWordsYouTubeVideo,
                EnunciationVideo1 = lesson.EnunciationVideo1,
                EnunciationVideo2 = lesson.EnunciationVideo2,
                MainIdea = lesson.MainIdea,
                SupportingIdea = lesson.SupportingIdea,
                StoryDetails = lesson.StoryDetails,
                StoryQuestions = lesson.StoryQuestions,
                ImportantSentencesForWordScramble = lesson.ImportantSentencesForWordScramble,
                LessonAuthor = existingUser
            });
        }