Katalog fix

This commit is contained in:
Naumann 2020-06-04 11:38:01 +02:00
parent b1f62f89e7
commit bb3f2f3fd0
2 changed files with 16 additions and 7 deletions

Binary file not shown.

View file

@ -52,17 +52,22 @@ namespace BuecherwurmAPI.Models
return books; return books;
} }
public Book GetBookById(long id) public Book GetBookById(long id)
{ {
Book book = new Book{};
using (var command = _dbConnection.CreateCommand()) using (var command = _dbConnection.CreateCommand())
{ {
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id; command.Parameters.Add(new SqliteParameter("@id", id));
command.CommandText = @"SELECT * FROM Books WHERE ProductId = @id"; command.CommandText = @"SELECT * FROM Books WHERE ProductId = @id";
var dataReader = command.ExecuteReader(); var dataReader = command.ExecuteReader();
var book = new Book while (dataReader.Read())
{ {
Name = (string) dataReader["Books"], book =new Book
{
Name = (string) dataReader["Name"],
Author = (string) dataReader["Author"], Author = (string) dataReader["Author"],
Country = (string) dataReader["Country"], Country = (string) dataReader["Country"],
Link = (string) dataReader["Link"], Link = (string) dataReader["Link"],
@ -77,13 +82,17 @@ namespace BuecherwurmAPI.Models
}; };
return book; return book;
} }
return null;
}
} }
public void DeleteBook(long id) public void DeleteBook(long id)
{ {
using (var command = _dbConnection.CreateCommand()) using (var command = _dbConnection.CreateCommand())
{ {
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id; command.Parameters.Add(new SqliteParameter("@id", id));
command.CommandText = @"DELETE * FROM Books WHERE ProductId= @id"; command.CommandText = @"DELETE FROM Books WHERE ProductId= @id";
var dataReader = command.ExecuteReader(); var dataReader = command.ExecuteReader();
} }
} }