From bd0f852d9be96c1282702fefa0da0cea9aad98ce Mon Sep 17 00:00:00 2001 From: David Renner Date: Tue, 2 Jun 2020 16:01:17 +0200 Subject: [PATCH] =?UTF-8?q?zwischenstand=20-=20nicht=20funktionst=C3=BCcht?= =?UTF-8?q?ig!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/ItemController.cs | 19 ++++++++++--------- Models/IItemRepo.cs | 4 ++-- Models/ItemModel.cs | 11 +++++++---- Models/ItemPost.cs | 11 +++++++++++ 4 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 Models/ItemPost.cs diff --git a/Controllers/ItemController.cs b/Controllers/ItemController.cs index 7e400b1..50618a5 100644 --- a/Controllers/ItemController.cs +++ b/Controllers/ItemController.cs @@ -28,7 +28,7 @@ namespace BuecherwurmAPI.Controllers // POST Inventar [HttpPost] - public ActionResult> NewItem(int bookId) + public ActionResult> NewItem(ItemPost item) { return Ok(new Item { @@ -40,7 +40,7 @@ namespace BuecherwurmAPI.Controllers // GET Inventar/{id} - [HttpGet("{id}", Name = "GetItemByID")] + [HttpGet("{itemId}")] public ActionResult> GetItemByID(int id) { var item = _repository.GetItemById(id); @@ -54,14 +54,15 @@ namespace BuecherwurmAPI.Controllers // DELETE inventory/{id} - [HttpDelete("id")] - public ActionResult> DeleteItem(int id) + + [HttpDelete("itemId")] + public ActionResult> DeleteItem(int itemId) { - var item = _repository.GetItemById(id); - if (item == null) - { - return NotFound(); - } + var item = _repository.GetItemById(itemId); + if(item == null) + { + return NotFound(); + } _repository.DeleteItem(item); return NoContent(); } diff --git a/Models/IItemRepo.cs b/Models/IItemRepo.cs index 46d7f62..f8a0b04 100644 --- a/Models/IItemRepo.cs +++ b/Models/IItemRepo.cs @@ -6,8 +6,8 @@ namespace BuecherwurmAPI.Models public interface IItemRepo { IEnumerable GetAllItems(); - Item GetItemById(int id); - void NewItem(Item item); + Item GetItemById(int itemId); + void NewItem(ItemPost item); void DeleteItem(Item item); } } \ No newline at end of file diff --git a/Models/ItemModel.cs b/Models/ItemModel.cs index ff6d83e..5ae273d 100644 --- a/Models/ItemModel.cs +++ b/Models/ItemModel.cs @@ -88,21 +88,24 @@ namespace BuecherwurmAPI.Models } return null; } - public Item NewItem(int bookId) + public Item NewItem(ItemPost itemPost) { using (var command = _dbConnection.CreateCommand()) { //hier soll jetz der NewItem Command folgen. ein POST mit EingabeInfo {id} = "BookId" - command.CommandText = @"INSERT INTO Item(ItemId,BookId) OUTPUT INSERTED.ID VALUES (@ItemID,@BookId"; + command.CommandText = "INSERT INTO Item(BOOKID) VALUES (@item)"; + command.CommandType = System.Data.CommandType.Text; + command.Parameters.Add(new SqliteParameter("@ITEMID", itemPost) + item; return item; } } - public void DeleteItem(Item item) + public void DeleteItem(int itemId) { using (var command = _dbConnection.CreateCommand()) { - command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = item; + command.Parameters.Add(new SqliteParameter("@id", SqliteType.Integer)).Value = itemId; //hier soll jetz der NewItem Command folgen. ein POST mit EingabeInfo {id} = "BookId" command.CommandText = @"SELECT * FROM Items WHERE ItemId = @id"; diff --git a/Models/ItemPost.cs b/Models/ItemPost.cs new file mode 100644 index 0000000..981c119 --- /dev/null +++ b/Models/ItemPost.cs @@ -0,0 +1,11 @@ +using System.ComponentModel.DataAnnotations; + +namespace BuecherwurmAPI.Models +{ + public class ItemPost + { + [Required] + public int BookId { get; set; } + } + +} \ No newline at end of file