Compare commits
No commits in common. "master" and "Amedeo" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,8 +11,6 @@
|
||||||
*.userosscache
|
*.userosscache
|
||||||
*.sln.docstates
|
*.sln.docstates
|
||||||
|
|
||||||
*.db
|
|
||||||
|
|
||||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
*.userprefs
|
*.userprefs
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace BuecherwurmAPI.Controllers
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult<LendPost> LendsPost(LendPost lend)
|
public ActionResult<LendPost> LendsPost(LendPost lend)
|
||||||
{
|
{
|
||||||
var newId = _repository.AddLend(lend);
|
var newId = _repository.insertLendReturningId(lend);
|
||||||
if (newId > 0)
|
if (newId > 0)
|
||||||
{
|
{
|
||||||
var item = new Lend
|
var item = new Lend
|
||||||
|
@ -68,12 +68,11 @@ namespace BuecherwurmAPI.Controllers
|
||||||
return Ok(lend);
|
return Ok(lend);
|
||||||
}
|
}
|
||||||
|
|
||||||
//PUT api/leihvorgang/{id}
|
//PATCH api/leihvorgang/{id}
|
||||||
[HttpPut("{id}")]
|
[HttpPatch("{id}")]
|
||||||
public ActionResult LendPatchById(long id, LendPost lend)
|
public ActionResult LendPatchById(int id, JsonPatchDocument<Lend> patchDocument)
|
||||||
{
|
{
|
||||||
var lendPatch = _repository.insertLendReturningId(id, lend);
|
return Ok();
|
||||||
return Ok(lendPatch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -113,15 +113,13 @@ namespace BuecherwurmAPI.Models
|
||||||
}
|
}
|
||||||
return book;
|
return book;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public void DeleteProduct(long id)
|
public void DeleteProduct(long id)
|
||||||
{
|
{
|
||||||
using (var command = _dbConnection.CreateCommand())
|
using (var command = _dbConnection.CreateCommand())
|
||||||
{
|
{
|
||||||
command.Parameters.Add(new SqliteParameter("@id", id));
|
command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = id;
|
||||||
command.CommandText = @"DELETE FROM Products WHERE ProductId= @id";
|
command.CommandText = @"DELETE * FROM Produkts WHERE ProductId= @id";
|
||||||
var dataReader = command.ExecuteReader();
|
var dataReader = command.ExecuteReader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +128,8 @@ namespace BuecherwurmAPI.Models
|
||||||
{
|
{
|
||||||
using (var command = _dbConnection.CreateCommand())
|
using (var command = _dbConnection.CreateCommand())
|
||||||
{
|
{
|
||||||
|
// funktioniert das so?
|
||||||
|
//muss ProduktId übergeben werden? -> ProductId wird weiter hinten mit 'NULL' befüllt, damit die ID automatisch vergeben wird.
|
||||||
command.CommandText = @"INSERT INTO Products (ProductId, Title, Author, Country, Link, Language, Pages, Year, Category, ImageLink, LendTime, LendType, Run, Audience, Topic) VALUES (NULL, @Title, @Author, @Country, @Link, @Language, @Pages, @Year, @Category, @ImageLink, @LendTime, @LendType, @Run, @Audience, @Topic)";
|
command.CommandText = @"INSERT INTO Products (ProductId, Title, Author, Country, Link, Language, Pages, Year, Category, ImageLink, LendTime, LendType, Run, Audience, Topic) VALUES (NULL, @Title, @Author, @Country, @Link, @Language, @Pages, @Year, @Category, @ImageLink, @LendTime, @LendType, @Run, @Audience, @Topic)";
|
||||||
|
|
||||||
command.Parameters.Add(new SqliteParameter("@Title", book.Title));
|
command.Parameters.Add(new SqliteParameter("@Title", book.Title));
|
||||||
|
@ -214,7 +214,7 @@ namespace BuecherwurmAPI.Models
|
||||||
command.Parameters.Add(new SqliteParameter("@Topic", ((MagazinPost)book).Topic));
|
command.Parameters.Add(new SqliteParameter("@Topic", ((MagazinPost)book).Topic));
|
||||||
}
|
}
|
||||||
|
|
||||||
command.ExecuteNonQuery();
|
var success = command.ExecuteNonQuery();
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,5 @@ namespace BuecherwurmAPI.Models
|
||||||
public DateTime ReturnDate {get; set;}
|
public DateTime ReturnDate {get; set;}
|
||||||
|
|
||||||
public string Customer {get; set;}
|
public string Customer {get; set;}
|
||||||
|
|
||||||
public bool Returned { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,43 +101,14 @@ namespace BuecherwurmAPI.Models
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long insertLendReturningId(long id, LendPost lend)
|
public long insertLendReturningId(LendPost lend)
|
||||||
{
|
{
|
||||||
using (var command = _dbConnection.CreateCommand())
|
using (var command = _dbConnection.CreateCommand())
|
||||||
{
|
{
|
||||||
command.CommandText = "UPDATE Lends SET (ItemId, ReturnDate, Customer, Returned) = (@itemId, @returnDate, @customer, @returned) WHERE Id = @id";
|
command.CommandText = "INSERT INTO Lends VALUES (NULL, @itemId, @returnDate, @customer, false)";
|
||||||
|
|
||||||
command.Parameters.Add(new SqliteParameter("@id", id));
|
|
||||||
command.Parameters.Add(new SqliteParameter("@itemId", lend.ItemId));
|
command.Parameters.Add(new SqliteParameter("@itemId", lend.ItemId));
|
||||||
command.Parameters.Add(new SqliteParameter("@returnDate", lend.ReturnDate));
|
command.Parameters.Add(new SqliteParameter("@returnDate", lend.ReturnDate));
|
||||||
command.Parameters.Add(new SqliteParameter("@customer", lend.Customer));
|
command.Parameters.Add(new SqliteParameter("@customer", lend.Customer));
|
||||||
command.Parameters.Add(new SqliteParameter("@returned", lend.Returned));
|
|
||||||
|
|
||||||
|
|
||||||
var success = command.ExecuteNonQuery();
|
|
||||||
|
|
||||||
if (success == 1)
|
|
||||||
{
|
|
||||||
command.CommandText = @"SELECT last_insert_rowid()";
|
|
||||||
return (long)command.ExecuteScalar();
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long AddLend (LendPost lend)
|
|
||||||
{
|
|
||||||
using (var command = _dbConnection.CreateCommand())
|
|
||||||
{
|
|
||||||
// funktioniert das so?
|
|
||||||
//muss ProduktId übergeben werden?
|
|
||||||
command.CommandText = @"INSERT INTO Lends (itemid, ReturnDate, Customer, Returned) VALUES (@ItemId, @ReturnDate, @Customer, false)";
|
|
||||||
|
|
||||||
command.Parameters.Add(new SqliteParameter("@ItemId", lend.ItemId));
|
|
||||||
command.Parameters.Add(new SqliteParameter("@ReturnDate", lend.ReturnDate));
|
|
||||||
command.Parameters.Add(new SqliteParameter("@Customer", lend.Customer));
|
|
||||||
|
|
||||||
var success = command.ExecuteNonQuery();
|
var success = command.ExecuteNonQuery();
|
||||||
|
|
||||||
|
|
14
Program.cs
14
Program.cs
|
@ -41,22 +41,12 @@ namespace BuecherwurmAPI
|
||||||
//var importedMags = JsonSerializer.Deserialize<List<Models.BookPost>>(magazinesJson);
|
//var importedMags = JsonSerializer.Deserialize<List<Models.BookPost>>(magazinesJson);
|
||||||
List<Models.IProductPost> imports = new List<Models.IProductPost>();
|
List<Models.IProductPost> imports = new List<Models.IProductPost>();
|
||||||
imports.AddRange(importedBooks);
|
imports.AddRange(importedBooks);
|
||||||
foreach (var item in importedBooks)
|
|
||||||
{
|
|
||||||
item.LendType = LendTypeEnum.Virtual;
|
|
||||||
item.Category = Models.CategoryEnum.EBook;
|
|
||||||
imports.Add(item);
|
|
||||||
}
|
|
||||||
//imports.AddRange(importedMags);
|
//imports.AddRange(importedMags);
|
||||||
|
|
||||||
|
var model = new Models.KatalogModel();
|
||||||
foreach (var item in imports)
|
foreach (var item in imports)
|
||||||
{
|
{
|
||||||
var id = catalogue.AddProduct(item);
|
model.AddProduct(item);
|
||||||
items.NewItem(new Models.ItemPost{ BookId = (int)id});
|
|
||||||
if (item.LendType != LendTypeEnum.Virtual)
|
|
||||||
{
|
|
||||||
items.NewItem(new Models.ItemPost{ BookId = (int)id});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue