예제 #1
0
        public async Task <IActionResult> Post([FromBody] BookCreateRequestModel model)
        {
            var authorExists = await this.authors.ExistsAsync(model.AuthorId);

            if (!authorExists)
            {
                return(BadRequest("Author does not exists."));
            }

            var categoryIds = await this.categories.CreateMultipleAsync(model.Categories);

            var titleExists = await this.books.TitleExistsAsync(model.Title);

            if (titleExists)
            {
                return(BadRequest($@"Book with ""{model.Title}"" title already exists."));
            }

            var bookId = await this.books.CreateAsync(
                model.AuthorId,
                model.Title,
                model.Description,
                model.Price,
                model.Copies,
                model.Edition,
                model.AgeRestriction,
                model.ReleaseDate,
                categoryIds);

            return(this.OkOrNotFound(bookId));
        }
        public async Task <IActionResult> Post([FromBody] BookCreateRequestModel book)
        {
            if (!await authorService.AuthorExistsAsync(book.AuthorId))
            {
                return(BadRequest("Author does not exist."));
            }

            int bookId = await bookService.CreateBookAsync(book.Title, book.Description, book.Price,
                                                           book.Copies, book.Edition, book.AuthorId, book.Categories);

            return(this.Ok(bookId));
        }