Browse Source

fixed AddBook and EditBook

Amedeo
Naumann 2 years ago
parent
commit
a1ffee2e09
  1. 2
      Controllers/KatalogController.cs
  2. 4
      Models/IBookRepo.cs
  3. 17
      Models/KatalogModel.cs

2
Controllers/KatalogController.cs

@ -90,7 +90,7 @@ namespace BuecherwurmAPI.Controllers
{
return NotFound();
}
_repository.DeleteBook(book);
_repository.DeleteBook(id);
return NoContent();
}

4
Models/IBookRepo.cs

@ -7,8 +7,8 @@ namespace BuecherwurmAPI.Models
{
IEnumerable<Book> GetAllBooks();
Book GetBookById(long id);
void DeleteBook(Book book);
void DeleteBook(long id);
void AddBook (Book book);
void EditBook (Book book);
void EditBook (long id, Book book);
}
}

17
Models/KatalogModel.cs

@ -74,12 +74,12 @@ namespace BuecherwurmAPI.Models
return book;
}
}
public void DeleteBook(Book book)
public void DeleteBook(long id)
{
using (var command = _dbConnection.CreateCommand())
{
// funktioniert das so?
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = book.ProductId;
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id;
command.CommandText = @"DELETE * FROM Books WHERE ProductId= @id";
var dataReader = command.ExecuteReader();
}
@ -90,15 +90,20 @@ namespace BuecherwurmAPI.Models
using (var command = _dbConnection.CreateCommand())
{
// funktioniert das so?
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = book.ProductId;
command.CommandText = @"INSERT INTO Books (Name, Author, Country, Link, Language, Pages, Year, ProductId, Category, ImageLink, LendTime, LendType) ";
command.CommandText = @"INSERT INTO Books (Name, Author, Country, Link, Language, Pages, Year, ProductId, Category, ImageLink, LendTime, LendType) VALUES (book.Name, book.Author, book.Contry, book.Link, book.Language, book.Pages, book.Year, book.ProductId, book.Category, book.ImageLink, book.LendTime, book.LendType)";
var dataReader = command.ExecuteReader();
}
}
public void EditBook (Book book)
public void EditBook (long id, Book book)
{
using (var command = _dbConnection.CreateCommand())
{
// funktioniert das so?
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id;
command.CommandText = @"INSERT INTO Books (Name, Author, Country, Link, Language, Pages, Year, ProductId, Category, ImageLink, LendTime, LendType)VALUES (book.Name, book.Author, book.Contry, book.Link, book.Language, book.Pages, book.Year, book.ProductId, book.Category, book.ImageLink, book.LendTime, book.LendType) WHERE ProductId = @id";
var dataReader = command.ExecuteReader();
}
}
}

Loading…
Cancel
Save