Пример #1
0
        /* public ActionResult<Book> Create(Book book)
         * {
         *  _chapterService.Create(book);
         *
         *  return CreatedAtRoute("GetBook", new { id = book.Id.ToString() }, book);
         * } */
        public async Task <IActionResult> CreateChapter([FromBody] Chapter newBookDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var isCreated = await _chapterService.CreateChapter(newBookDetails);

            if (isCreated == false)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Пример #2
0
 public async Task <ApiResponse <Chapter> > CreateChapter(ChapterDto chapter)
 {
     try
     {
         return(await _chapterService.CreateChapter(chapter));
     }
     catch (Exception ex)
     {
         return(new ApiResponse <Chapter>()
         {
             Success = false, Errors = new List <string>()
             {
                 ex.Message
             }
         });
     }
 }