Browse Source

bug fix

Felix
Naumann 2 years ago
parent
commit
8d81ab4843
  1. 7
      Controllers/LendController.cs
  2. BIN
      LongWormMemory.db
  3. 2
      Models/Lend.cs
  4. 31
      Models/LendModel.cs

7
Controllers/LendController.cs

@ -35,7 +35,7 @@ namespace BuecherwurmAPI.Controllers
[HttpPost]
public ActionResult<LendPost> 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<Lend> patchDocument)
[HttpPut("{id}")]
public ActionResult LendPatchById(long id, LendPost lend)
{
_repository.insertLendReturningId(id, lend);
return Ok();
}
}

BIN
LongWormMemory.db

Binary file not shown.

2
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; }
}
}

31
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();

Loading…
Cancel
Save