public BaseResponse <ChapterDetailOutputDto> Create(ChapterInputDto chapterInputDto) { if (Contains(c => c.BookId == chapterInputDto.BookId && c.ChapterIndex == chapterInputDto.ChapterIndex)) { throw new BadRequestException($"Chapter với index {chapterInputDto.ChapterIndex} đã tồn tại"); } var chapter = Create(Mapper.Map <Chapter>(chapterInputDto), out var isSaved); if (!isSaved) { throw new InternalServerErrorException($"Không thể tạo chapter {chapterInputDto.Name}"); } return(new BaseResponse <ChapterDetailOutputDto>(HttpStatusCode.OK, data: Mapper.Map <ChapterDetailOutputDto>(chapter))); }
public BaseResponse <bool> Update(Guid id, ChapterInputDto chapterInputDto) { var oldChapter = Find(id); if (oldChapter == null) { throw new BadRequestException($"Không tìm thấy chương {id}"); } oldChapter.Name = chapterInputDto.Name; oldChapter.Content = chapterInputDto.Content; var isSaved = Update(oldChapter); if (!isSaved) { throw new InternalServerErrorException($"Không thể update chương {chapterInputDto.Name}"); } return(new BaseResponse <bool>(HttpStatusCode.OK, data: true)); }
public BaseResponse <bool> Update(Guid id, [FromBody] ChapterInputDto chapterInputDto) { return(_chapterService.Update(id, chapterInputDto)); }
public BaseResponse <ChapterDetailOutputDto> Create([FromBody] ChapterInputDto chapterInputDto) { return(_chapterService.Create(chapterInputDto)); }