diff --git a/Aps Single Page Anwendung/Controllers/SpeisenController.cs b/Aps Single Page Anwendung/Controllers/SpeisenController.cs index fb44f4e..3447e15 100644 --- a/Aps Single Page Anwendung/Controllers/SpeisenController.cs +++ b/Aps Single Page Anwendung/Controllers/SpeisenController.cs @@ -72,7 +72,17 @@ namespace Aps_Single_Page_Anwendung.Controllers } var result = _repository.UpdateSpeise(speise); return Ok(result); + } + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + if(_repository.GetSpeiseById(id) == null) + { + return NotFound(); + } + _repository.DeleteSpeise(id); + return NoContent(); } } diff --git a/Aps Single Page Anwendung/Repositories/FileSpeiseRepository.cs b/Aps Single Page Anwendung/Repositories/FileSpeiseRepository.cs index b446bcd..626fdc1 100644 --- a/Aps Single Page Anwendung/Repositories/FileSpeiseRepository.cs +++ b/Aps Single Page Anwendung/Repositories/FileSpeiseRepository.cs @@ -39,9 +39,11 @@ namespace Aps_Single_Page_Anwendung.Repositories } + // Löschen der Speise public void DeleteSpeise(int id) { - throw new System.NotImplementedException(); + var speisen = GetSpeisen().Where(speise_ => speise_.Id != id).ToList(); + Filesave(speisen); } @@ -79,7 +81,7 @@ namespace Aps_Single_Page_Anwendung.Repositories { var options = new JsonSerializerOptions { - WriteIndented = true // Zeilenumbrüche + WriteIndented = true // Zeilenumbrüche bzw Daten werden eingerückt }; var json = JsonSerializer.Serialize(speisen, options); File.WriteAllText(_path, json); // schreibt ins File diff --git a/Aps Single Page Anwendung/data/speisen.json b/Aps Single Page Anwendung/data/speisen.json index 558381a..d562521 100644 --- a/Aps Single Page Anwendung/data/speisen.json +++ b/Aps Single Page Anwendung/data/speisen.json @@ -174,13 +174,5 @@ "Preis": 1.59, "KategorieId": 6, "Kategorie": null - }, - { - "Id": 23, - "Name": "Gemischter Salato", - "Beschreibung": "Salat nach Art des Hauses mit dem Besten aus der K\u00FCche. Gemischter Salat, Mais, Paprika, K\u00E4se, Zwiebeln, Orange", - "Preis": 19.49, - "KategorieId": 1, - "Kategorie": null } ] \ No newline at end of file