예제 #1
0
        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)));
        }
예제 #2
0
        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));
        }
예제 #3
0
 public BaseResponse <bool> Update(Guid id, [FromBody] ChapterInputDto chapterInputDto)
 {
     return(_chapterService.Update(id, chapterInputDto));
 }
예제 #4
0
 public BaseResponse <ChapterDetailOutputDto> Create([FromBody] ChapterInputDto chapterInputDto)
 {
     return(_chapterService.Create(chapterInputDto));
 }