Compare commits

...

20 commits

Author SHA1 Message Date
Naumann e7b3d2d742 . 2020-06-11 09:34:31 +02:00
nek0 a4b6d41a25 don't track any database 2020-06-05 11:59:26 +02:00
nek0 36cefe06ac remove database from repo 2020-06-05 11:57:39 +02:00
nek0 0fc3569322 Merge branch 'master' of https://gitea.nek0.eu/nek0/BuecherwurmAPI 2020-06-05 11:56:07 +02:00
nek0 f04f7f4892 generate ebooks from imports 2020-06-05 11:55:29 +02:00
Naumann 1ec245c6e2 small changes in KatalogModel 2020-06-04 15:31:47 +02:00
nek0 f94d8b2c65 make items from import 2020-06-04 14:24:52 +02:00
nek0 ea81721be3 Merge branch 'master' of https://gitea.nek0.eu/nek0/BuecherwurmAPI 2020-06-04 14:15:51 +02:00
nek0 4eaabe584b Merge branch 'Amedeo' 2020-06-04 14:08:20 +02:00
Naumann 4a6bb9313b Merge remote-tracking branch 'origin/Felix' 2020-06-04 14:06:54 +02:00
Naumann d545f31f65 . 2020-06-04 14:06:29 +02:00
Naumann bd4f034d7b zwischenstand 2020-06-04 13:43:01 +02:00
Naumann 8d81ab4843 bug fix 2020-06-04 12:23:32 +02:00
Naumann bb3f2f3fd0 Katalog fix 2020-06-04 11:38:01 +02:00
Naumann 74ecc0e285 new entry in db 2020-06-04 10:17:41 +02:00
Naumann b1f62f89e7 Merge branch 'master' of https://gitea.nek0.eu/nek0/BuecherwurmAPI into Felix 2020-06-04 09:35:10 +02:00
Naumann 3e369eff83 changed ENum to long 2020-06-04 09:34:31 +02:00
Naumann 942a7d321b . 2020-06-04 07:39:45 +02:00
Naumann cbfba6b578 Merge remote-tracking branch 'origin/master' into Felix 2020-06-03 13:45:19 +02:00
Naumann 7c62650341 Merge remote-tracking branch 'origin/master' into Felix 2020-06-03 13:44:21 +02:00
6 changed files with 58 additions and 14 deletions

2
.gitignore vendored
View file

@ -11,6 +11,8 @@
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
*.db
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs

View file

@ -35,7 +35,7 @@ namespace BuecherwurmAPI.Controllers
[HttpPost] [HttpPost]
public ActionResult<LendPost> LendsPost(LendPost lend) public ActionResult<LendPost> LendsPost(LendPost lend)
{ {
var newId = _repository.insertLendReturningId(lend); var newId = _repository.AddLend(lend);
if (newId > 0) if (newId > 0)
{ {
var item = new Lend var item = new Lend
@ -68,11 +68,12 @@ namespace BuecherwurmAPI.Controllers
return Ok(lend); return Ok(lend);
} }
//PATCH api/leihvorgang/{id} //PUT api/leihvorgang/{id}
[HttpPatch("{id}")] [HttpPut("{id}")]
public ActionResult LendPatchById(int id, JsonPatchDocument<Lend> patchDocument) public ActionResult LendPatchById(long id, LendPost lend)
{ {
return Ok(); var lendPatch = _repository.insertLendReturningId(id, lend);
return Ok(lendPatch);
} }
} }
} }

View file

@ -113,13 +113,15 @@ 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", SqliteType.Integer)).Value = id; command.Parameters.Add(new SqliteParameter("@id", id));
command.CommandText = @"DELETE * FROM Produkts WHERE ProductId= @id"; command.CommandText = @"DELETE FROM Products WHERE ProductId= @id";
var dataReader = command.ExecuteReader(); var dataReader = command.ExecuteReader();
} }
} }
@ -128,8 +130,6 @@ 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));
} }
var success = command.ExecuteNonQuery(); command.ExecuteNonQuery();
return id; return id;
} }

View file

@ -24,5 +24,7 @@ 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; }
} }
} }

View file

@ -101,14 +101,43 @@ namespace BuecherwurmAPI.Models
return null; return null;
} }
public long insertLendReturningId(LendPost lend) public long insertLendReturningId(long id, LendPost lend)
{ {
using (var command = _dbConnection.CreateCommand()) 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("@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();

View file

@ -41,12 +41,22 @@ 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)
{ {
model.AddProduct(item); var id = catalogue.AddProduct(item);
items.NewItem(new Models.ItemPost{ BookId = (int)id});
if (item.LendType != LendTypeEnum.Virtual)
{
items.NewItem(new Models.ItemPost{ BookId = (int)id});
}
} }
} }