Browse Source

Merge remote-tracking branch 'origin/Felix' into Amedeo

Amedeo
nek0 2 years ago
parent
commit
b79db9d800
  1. 2
      Controllers/KatalogController.cs
  2. 6
      Models/IBookRepo.cs
  3. 69
      Models/KatalogModel.cs

2
Controllers/KatalogController.cs

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

6
Models/IBookRepo.cs

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

69
Models/KatalogModel.cs

@ -74,19 +74,80 @@ namespace BuecherwurmAPI.Models
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…
Cancel
Save