fixed AddBook and EditBook
This commit is contained in:
parent
226faafafc
commit
a1ffee2e09
3 changed files with 14 additions and 9 deletions
|
@ -90,7 +90,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
_repository.DeleteBook(book);
|
||||
_repository.DeleteBook(id);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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…
Reference in a new issue