From 942a7d321b1cd83587166f5255ee41810e6b6a89 Mon Sep 17 00:00:00 2001 From: Naumann Date: Thu, 4 Jun 2020 07:39:45 +0200 Subject: [PATCH 1/4] . --- Controllers/KatalogController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Controllers/KatalogController.cs b/Controllers/KatalogController.cs index 0e4a68d..17828ec 100644 --- a/Controllers/KatalogController.cs +++ b/Controllers/KatalogController.cs @@ -70,6 +70,7 @@ namespace BuecherwurmAPI.Controllers // DELETE katalog/{id} [HttpDelete("{id}")] + public ActionResult DeleteBook (long id) { var book = _repository.GetBookById(id); From bb3f2f3fd00a1b2650d5e53d9adb71f5b377c342 Mon Sep 17 00:00:00 2001 From: Naumann Date: Thu, 4 Jun 2020 11:38:01 +0200 Subject: [PATCH 2/4] Katalog fix --- LongWormMemory.db | Bin 16384 -> 16384 bytes Models/KatalogModel.cs | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/LongWormMemory.db b/LongWormMemory.db index 2af348abd5cc5350f02eaa525bfd54ec7a21f55d..bc57600b15fb208782bcf5d3ad75dbb505ffbfc8 100644 GIT binary patch delta 316 zcmZo@U~Fh$oFL7pG*QNxQE6ksGJdXS4E!JY-|#=7BNH1nN4>XQa-~#=z(-&cSA6U}T_c zV5)0mp Date: Thu, 4 Jun 2020 12:23:32 +0200 Subject: [PATCH 3/4] bug fix --- Controllers/LendController.cs | 7 ++++--- LongWormMemory.db | Bin 16384 -> 16384 bytes Models/Lend.cs | 2 ++ Models/LendModel.cs | 31 +++++++++++++++++++++++++++++-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Controllers/LendController.cs b/Controllers/LendController.cs index f599103..47a7c37 100644 --- a/Controllers/LendController.cs +++ b/Controllers/LendController.cs @@ -35,7 +35,7 @@ namespace BuecherwurmAPI.Controllers [HttpPost] public ActionResult LendsPost(LendPost lend) { - var newId = _repository.insertLendReturningId(lend); + var newId = _repository.AddLend(lend); if (newId > 0) { var item = new Lend @@ -69,9 +69,10 @@ namespace BuecherwurmAPI.Controllers } //PATCH api/leihvorgang/{id} - [HttpPatch("{id}")] - public ActionResult LendPatchById(int id, JsonPatchDocument patchDocument) + [HttpPut("{id}")] + public ActionResult LendPatchById(long id, LendPost lend) { + _repository.insertLendReturningId(id, lend); return Ok(); } } diff --git a/LongWormMemory.db b/LongWormMemory.db index bc57600b15fb208782bcf5d3ad75dbb505ffbfc8..80df6e6d145b0a6a57fb283e231256021930897f 100644 GIT binary patch delta 182 zcmZo@U~Fh$oFL7pF;T{uQDbAm5_t(OzBm^Ci~O_sv-myuRr#6tZt`v5Yv+sGEGXc_ zSFg^+#=z(-&Y5ClU}T_cV5)0mpJo8rz{8nt41g3 delta 48 zcmZo@U~Fh$oFL7pG*QNxQE6ks5_utZzMCxk7x`!NXYqURtMW7P-P|lFaF}oNO+9r% E08c3m*#H0l diff --git a/Models/Lend.cs b/Models/Lend.cs index 50ba663..debbdf3 100644 --- a/Models/Lend.cs +++ b/Models/Lend.cs @@ -24,5 +24,7 @@ namespace BuecherwurmAPI.Models public DateTime ReturnDate {get; set;} public string Customer {get; set;} + + public bool Returned { get; set; } } } diff --git a/Models/LendModel.cs b/Models/LendModel.cs index 3c2bba7..62daeb4 100644 --- a/Models/LendModel.cs +++ b/Models/LendModel.cs @@ -101,14 +101,41 @@ namespace BuecherwurmAPI.Models return null; } - public long insertLendReturningId(LendPost lend) + public long insertLendReturningId(long id, LendPost lend) { using (var command = _dbConnection.CreateCommand()) { - command.CommandText = "INSERT INTO Lends VALUES (NULL, @itemId, @returnDate, @customer, false)"; + command.CommandText = "UPDATE Lends SET (ItemId, ReturnDate, Customer, Returned) = (@itemId, @returnDate, @customer, @returned) WHERE Id = @id"; + + command.Parameters.Add(new SqliteParameter("@id", id)); 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("@returned", lend.Returned)); + + + var success = command.ExecuteNonQuery(); + + if (success == 1) + { + 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(); From bd4f034d7b2f5dd56b47693e941677b0dde470d8 Mon Sep 17 00:00:00 2001 From: Naumann Date: Thu, 4 Jun 2020 13:43:01 +0200 Subject: [PATCH 4/4] zwischenstand --- Controllers/LendController.cs | 6 +++--- LongWormMemory.db | Bin 16384 -> 16384 bytes Models/KatalogModel.cs | 2 +- Models/LendModel.cs | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Controllers/LendController.cs b/Controllers/LendController.cs index 47a7c37..6f1d84d 100644 --- a/Controllers/LendController.cs +++ b/Controllers/LendController.cs @@ -68,12 +68,12 @@ namespace BuecherwurmAPI.Controllers return Ok(lend); } - //PATCH api/leihvorgang/{id} + //PUT api/leihvorgang/{id} [HttpPut("{id}")] public ActionResult LendPatchById(long id, LendPost lend) { - _repository.insertLendReturningId(id, lend); - return Ok(); + var lendPatch = _repository.insertLendReturningId(id, lend); + return Ok(lendPatch); } } } \ No newline at end of file diff --git a/LongWormMemory.db b/LongWormMemory.db index 80df6e6d145b0a6a57fb283e231256021930897f..394130a2b9eb7eb1e62b2acea3b4c0eb50e30b8e 100644 GIT binary patch delta 155 zcmZo@U~Fh$oFL6;I8nx#(QsozxE>Ry*5nC#itOxc42;g=oSPr&DKPRgFfcIl&0^x4 z#m~pz!zZ>`P=Jk(g};lTWwMlAg*cGGp)74%T*Sz$45Y;wnHU%&896754-O6%4i>W!5C#qedISw4lNvsF1ONa4e3KGCPLpUpDw7UBd=GR14I?8PJr@E3 V00CJ60h6gdIs^im2j!DtKPjlX843UZ diff --git a/Models/KatalogModel.cs b/Models/KatalogModel.cs index 5f9b390..e8a2d23 100644 --- a/Models/KatalogModel.cs +++ b/Models/KatalogModel.cs @@ -149,7 +149,7 @@ namespace BuecherwurmAPI.Models command.Parameters.Add(new SqliteParameter("@LendTime", book.LendTime)); command.Parameters.Add(new SqliteParameter("@LendType", book.LendType)); - var success = command.ExecuteNonQuery(); + command.ExecuteNonQuery(); return id; } diff --git a/Models/LendModel.cs b/Models/LendModel.cs index 62daeb4..f4407b9 100644 --- a/Models/LendModel.cs +++ b/Models/LendModel.cs @@ -118,10 +118,12 @@ namespace BuecherwurmAPI.Models if (success == 1) { + command.CommandText = @"SELECT last_insert_rowid()"; return (long)command.ExecuteScalar(); } return -1; + } }