Beispiel #1
0
        public async Task <IActionResult> GetBookById([FromRoute] string id)
        {
            var myBook = await _repository.GetByIdAsync <Book>(
                book => book.Id == id
                );

            return(Ok(BookModelDTO.FromBook(myBook)));
        }
Beispiel #2
0
        public async Task <IActionResult> AddBook([FromBody] BookModelDTO model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var addedBook = await _repository.AddAsync <Book>(BookModelDTO.FromBookDTO(model));

            return(Ok(BookModelDTO.FromBook(addedBook)));
        }
Beispiel #3
0
        public async Task <IActionResult> GetBookByName([FromRoute] string name)
        {
            var myBook = await _repository.GetByIdAsync <Book>(
                book => book.Reviews,
                book => book.Name == name
                );

            if (myBook == null)
            {
                return(BadRequest($"Book: {name} not found"));
            }

            return(Ok(BookModelDTO.FromBook(myBook)));
        }