public ActionResult <ChapterDto> Get(int chapterId, bool includeLessons = false) { var query = new GetChapterQuery(chapterId, allowPublishedCourse: true, includeLessons: includeLessons); return(getChapterQueryHandler.Handle(query) .OnSuccess((chapter) => MapToDto(chapter, includeLessons)) .OnBoth((result) => responseHandler.GetResponse(result))); }
public ActionResult <IEnumerable <LessonDto> > GetAllByChapter([FromQuery] int chapterId) { var query = new GetChapterQuery(chapterId, allowPublishedCourse: true, includeLessons: true); var chapterResult = getChapterQueryHandler.Handle(query); var lessonResult = chapterResult.Success ? Result.Ok(mapper.Map <IEnumerable <LessonDto> >(chapterResult.Value.Lessons.OrderBy(x => x.Order))) : Result.Fail <IEnumerable <LessonDto> >(chapterResult.Errors, chapterResult.StatusCode); return(responseHandler.GetResponse(lessonResult)); }
public Result <ChapterDto> Handle(UpdateChapterCommand command) { var query = new GetChapterQuery(command.ChapterId, allowPublishedCourse: true); return(getChapterQueryHandler.Handle(query) .OnSuccess((chapter) => uniqueChapterNameQueryHandler.Handle( new ChapterNameIsUniqueQuery(chapter.Course.Id, command.ChapterId, command.Name)) .OnSuccess(() => { chapter = mapper.Map(command, chapter); dbContext.SaveChanges(); return Result.Ok(mapper.Map <ChapterDto>(chapter)); }))); }
public async Task <ActionResult <ChapterModel> > GetChapter( [FromRoute] ChapterReference reference, CancellationToken cancellationToken) { var query = new GetChapterQuery(reference.SagaId, reference.ChapterId); try { var response = await _sender.Send(query, cancellationToken); return(Ok(_mapper.Map <ChapterModel>(response))); } catch (ChapterNotFoundException e) { return(NotFound(e.Message)); } }