-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooksController.cs
49 lines (46 loc) · 1.28 KB
/
BooksController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using csharp_webapi_example.Services;
using csharp_webapi_example.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace csharp_webapi_example.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BooksController : ControllerBase
{
private readonly BookService _bookService;
public BooksController(BookService bookService)
{
_bookService = bookService;
}
[HttpPost]
public IActionResult AddBook([FromBody] BookVM book)
{
_bookService.AddBookWithAuthors(book);
return Ok();
}
[HttpGet]
public IActionResult GetAllBooks()
{
var books = _bookService.GetAllBooks();
return Ok(books);
}
[HttpGet("{id}")]
public IActionResult GetBookById(int id)
{
var book = _bookService.GetBookById(id);
return Ok(book);
}
[HttpPut]
public IActionResult UpdateBook(int id, [FromBody]BookVM book)
{
var _book = _bookService.UpdateBookById(id, book);
return Ok(_book);
}
[HttpDelete]
public IActionResult DeleteBook(int id)
{
_bookService.Delete(id);
return Ok();
}
}
}