public IActionResult ReadAll([FromQuery] ReadAllChaptersDto readAllChaptersDto) { ReadAllChaptersResponseDto responseDto = null; try { if (_httpContextAccessor.GetCurrentUserId() != readAllChaptersDto.AuthorId) { throw new UnauthorizedAccessException($"Requested authorId does not match authenticated authorId."); } var lastReadAll = readAllChaptersDto.LastReadAll.HasValue ? readAllChaptersDto.LastReadAll.Value : new DateTime(1970, 1, 1); var lastReadAllResponse = DateTime.Now; var chapters = _chapterService.ReadAll(readAllChaptersDto.AuthorId, readAllChaptersDto.BookId, lastReadAll); responseDto = new ReadAllChaptersResponseDto { Chapters = chapters.Select(c => { var chapterResponseDto = _mapper.Map <ReadChapterResponseDto>(c); chapterResponseDto.Timeline = c.Timeline == null ? null : _mapper.Map <ReadTimelineResponseDto>(c.Timeline); return(chapterResponseDto); }).ToArray(), LastReadAll = lastReadAllResponse, }; } catch (Exception ex) { Console.WriteLine($"Encountered exception while attempting to read all chapters. Message: {ex.Message}"); Console.WriteLine(ex.StackTrace); return(BadRequest(new ErrorResponseDto(ex))); } return(Ok(responseDto)); }