// 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 }); }
public bool LessonEdit(Lesson lessonModel) { return lessonRepository.Update(lessonModel); }