diff --git a/Controllers/KatalogController.cs b/Controllers/KatalogController.cs index d7c4d52..63fb7be 100644 --- a/Controllers/KatalogController.cs +++ b/Controllers/KatalogController.cs @@ -90,7 +90,7 @@ namespace BuecherwurmAPI.Controllers { return NotFound(); } - _repository.DeleteBook(book); + _repository.DeleteBook(id); return NoContent(); } diff --git a/Models/IBookRepo.cs b/Models/IBookRepo.cs index 9d4aca2..bd13521 100644 --- a/Models/IBookRepo.cs +++ b/Models/IBookRepo.cs @@ -7,8 +7,8 @@ namespace BuecherwurmAPI.Models { IEnumerable 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); } } \ No newline at end of file diff --git a/Models/KatalogModel.cs b/Models/KatalogModel.cs index 7e28488..f5e5823 100644 --- a/Models/KatalogModel.cs +++ b/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(); + } } }