Merge remote-tracking branch 'origin/Felix' into Amedeo
This commit is contained in:
commit
b79db9d800
3 changed files with 69 additions and 8 deletions
|
@ -90,7 +90,7 @@ namespace BuecherwurmAPI.Controllers
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
_repository.DeleteBook(book);
|
_repository.DeleteBook(id);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ namespace BuecherwurmAPI.Models
|
||||||
{
|
{
|
||||||
IEnumerable<Book> GetAllBooks();
|
IEnumerable<Book> GetAllBooks();
|
||||||
Book GetBookById(long id);
|
Book GetBookById(long id);
|
||||||
void DeleteBook(Book book);
|
void DeleteBook(long id);
|
||||||
void AddBook (Book book);
|
long AddBook (Book book);
|
||||||
void EditBook (Book book);
|
long EditBook (long id, Book book);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -74,19 +74,80 @@ namespace BuecherwurmAPI.Models
|
||||||
return book;
|
return book;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DeleteBook(Book book)
|
public void DeleteBook(long id)
|
||||||
{
|
{
|
||||||
|
using (var command = _dbConnection.CreateCommand())
|
||||||
|
{
|
||||||
|
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id;
|
||||||
|
command.CommandText = @"DELETE * FROM Books WHERE ProductId= @id";
|
||||||
|
var dataReader = command.ExecuteReader();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddBook (Book book)
|
public long AddBook (Book book)
|
||||||
{
|
{
|
||||||
|
using (var command = _dbConnection.CreateCommand())
|
||||||
|
{
|
||||||
|
// funktioniert das so?
|
||||||
|
//muss ProduktId übergeben werden?
|
||||||
|
command.CommandText = @"INSERT INTO Books (Name, Author, Country, Link, Language, Pages, Year, ProductId, Category, ImageLink, LendTime, LendType) VALUES (@Name, @Author, @Country, @Link, @Language, @Pages, @Year, @ProductId, @Category, @ImageLink, @LendTime, @LendType )";
|
||||||
|
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Name", book.Name));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Author", book.Author));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Contry", book.Country));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Link", book.Link));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Language", book.Language));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Pages", book.Pages));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Year", book.Year));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@ProductId", book.ProductId));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Category", book.Category));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@ImageLink", book.ImageLink));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@LendTime", book.LendTime));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@LendType", book.LendType));
|
||||||
|
|
||||||
|
var success = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
if (success == 1)
|
||||||
|
{
|
||||||
|
command.CommandText = @"SELECT last_insert_rowid()";
|
||||||
|
return (long)command.ExecuteScalar();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EditBook (Book book)
|
public long 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 (@Name, @Author, @Country, @Link, @Language, @Pages, @Year, @ProductId, @Category, @ImageLink, @LendTime, @LendType )";
|
||||||
|
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Name", book.Name));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Author", book.Author));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Contry", book.Country));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Link", book.Link));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Language", book.Language));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Pages", book.Pages));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Year", book.Year));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@ProductId", book.ProductId));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@Category", book.Category));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@ImageLink", book.ImageLink));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@LendTime", book.LendTime));
|
||||||
|
command.Parameters.Add(new SqliteParameter("@LendType", book.LendType));
|
||||||
|
|
||||||
|
var success = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
if (success == 1)
|
||||||
|
{
|
||||||
|
command.CommandText = @"SELECT last_insert_rowid()";
|
||||||
|
return (long)command.ExecuteScalar();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue