99 lines
No EOL
2.6 KiB
C#
99 lines
No EOL
2.6 KiB
C#
using System.Collections.Generic;
|
|
using BuecherwurmAPI.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq;
|
|
//using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BuecherwurmAPI.Controllers
|
|
{
|
|
[Route("katalog") ]
|
|
[ApiController]
|
|
public class KatalogController :ControllerBase
|
|
{
|
|
private readonly IBookRepo _repository;
|
|
|
|
public KatalogController (IBookRepo repository)
|
|
{
|
|
_repository=repository;
|
|
}
|
|
// GET Katalog
|
|
[HttpGet]
|
|
public ActionResult<IEnumerable<Book>> GetAllBooks()
|
|
{
|
|
var books =_repository.GetAllBooks();
|
|
return Ok(books);
|
|
}
|
|
|
|
// POST Katalog
|
|
[HttpPost]
|
|
public ActionResult<IEnumerable<Book>> AddBook(Book book)
|
|
{
|
|
|
|
return Ok(new Book
|
|
{
|
|
Name = book.Name,
|
|
Author= book.Author,
|
|
Country= book.Country,
|
|
Link= book.Link,
|
|
Language= book.Language,
|
|
Pages= book.Pages,
|
|
Year=book.Year,
|
|
ProductId =book.ProductId,
|
|
Category= book.Category,
|
|
ImageLink =book.ImageLink,
|
|
LendTime =book.LendTime,
|
|
LendType = book.LendType
|
|
});
|
|
}
|
|
|
|
|
|
// GET katalog/{id}
|
|
[HttpGet("{id}", Name ="GetBookByID")]
|
|
public ActionResult <IEnumerable<Book>> GetBookByID(long id)
|
|
{
|
|
var book = _repository.GetBookById(id);
|
|
if (book != null)
|
|
{
|
|
return Ok(book);
|
|
}
|
|
return NoContent();
|
|
|
|
}
|
|
|
|
// PUT Katalog/{id}
|
|
[HttpPut("id")]
|
|
public ActionResult<IEnumerable<Book>> EditBook(Book book)
|
|
{
|
|
return Ok(new Book
|
|
{
|
|
Name = book.Name,
|
|
Author= book.Author,
|
|
Country= book.Country,
|
|
Link= book.Link,
|
|
Language= book.Language,
|
|
Pages= book.Pages,
|
|
Year=book.Year,
|
|
ProductId =book.ProductId,
|
|
Category= book.Category,
|
|
ImageLink =book.ImageLink,
|
|
LendTime =book.LendTime,
|
|
LendType = book.LendType
|
|
});
|
|
}
|
|
|
|
// DELETE katalog/{id}
|
|
[HttpDelete("id")]
|
|
public ActionResult<IEnumerable<Book>> DeleteBook (long id)
|
|
{
|
|
var book = _repository.GetBookById(id);
|
|
if(book == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
_repository.DeleteBook(book);
|
|
return NoContent();
|
|
}
|
|
|
|
}
|
|
|
|
} |