.
This commit is contained in:
parent
8b4c0c1e54
commit
ae3cbb0cd3
3 changed files with 43 additions and 12 deletions
|
@ -32,7 +32,7 @@ namespace BuecherwurmAPI.Controllers
|
|||
var itemid = insertItemReturningId(bookId);
|
||||
return Ok(new Item
|
||||
{
|
||||
Id = itemId,
|
||||
Id = itemid,
|
||||
BookId = bookId,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace BuecherwurmAPI.Models
|
|||
IEnumerable<Book> GetAllBooks();
|
||||
Book GetBookById(long id);
|
||||
void DeleteBook(long id);
|
||||
void AddBook (Book book);
|
||||
void EditBook (long id, Book book);
|
||||
long AddBook (Book book);
|
||||
long EditBook (long id, Book book);
|
||||
}
|
||||
}
|
|
@ -78,23 +78,32 @@ namespace BuecherwurmAPI.Models
|
|||
{
|
||||
using (var command = _dbConnection.CreateCommand())
|
||||
{
|
||||
// funktioniert das so?
|
||||
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?
|
||||
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)";
|
||||
//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("@itemId", lend.ItemId));
|
||||
command.Parameters.Add(new SqliteParameter("@returnDate", lend.ReturnDate));
|
||||
command.Parameters.Add(new SqliteParameter("@customer", lend.Customer));
|
||||
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();
|
||||
|
||||
|
@ -108,14 +117,36 @@ namespace BuecherwurmAPI.Models
|
|||
}
|
||||
}
|
||||
|
||||
public void EditBook (long id, 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 (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();
|
||||
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