Пример #1
0
        public IActionResult Update([FromBody] UpdateChapterDto chapterDto)
        {
            UpdateChapterResponseDto responseDto = null;

            try
            {
                if (_httpContextAccessor.GetCurrentUserId() != chapterDto.AuthorId)
                {
                    throw new UnauthorizedAccessException("You are not authorized to update the specified chapter.");
                }

                var chapterEntity = _chapterService.UpdateChapter(
                    chapterDto.ChapterId,
                    chapterDto.AuthorId,
                    chapterDto.BookId,
                    chapterDto.TimelineId,
                    chapterDto.SortOrder,
                    chapterDto.Title,
                    chapterDto.Body);
                responseDto          = _mapper.Map <UpdateChapterResponseDto>(chapterEntity);
                responseDto.Timeline = chapterEntity.Timeline == null
                    ? null
                    : _mapper.Map <ReadTimelineResponseDto>(chapterEntity.Timeline);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Encountered exception while attempting to update chapter.  Message: {ex.Message}");
                Console.WriteLine(ex.StackTrace);
                return(BadRequest(new ErrorResponseDto(ex)));
            }

            return(Ok(responseDto));
        }
Пример #2
0
 public IHttpActionResult UpdateChapter(Chapter chapter)
 {
     return(Ok(new { results = chapterService.UpdateChapter(chapter) }));
 }
Пример #3
0
 public string UpdateChapter(Guid userId, [FromBody] ChapterDTO chapter)
 {
     return(chapterService.UpdateChapter(userId, chapter) ? "Success" : "Fail");
 }
Пример #4
0
 public IActionResult Put(int id, [FromBody] Chapter value)
 {
     service.UpdateChapter(id, value);
     return(Ok(value));
 }
Пример #5
0
        /// <summary>
        /// 更新章节
        /// </summary>
        /// <param name="editChapterInput"></param>
        /// <returns></returns>
        public async Task <ChapterOutput> UpdateEditChapter(EditChapterInput editChapterInput)
        {
            var editChapter = await _chapterService.UpdateChapter(editChapterInput.Adapt <ChapterDto>());

            return(editChapter.Adapt <ChapterOutput>());
        }