diff --git a/Francesco.Recipes.World/Views/Recipe/AddInstruction.cshtml b/Francesco.Recipes.World/Views/Recipe/AddInstruction.cshtml index d6d5f79..e2ce85d 100644 --- a/Francesco.Recipes.World/Views/Recipe/AddInstruction.cshtml +++ b/Francesco.Recipes.World/Views/Recipe/AddInstruction.cshtml @@ -24,36 +24,38 @@ -
- - -
- + + @section Scripts { - if (response.ok) { - location.reload(); - } else { - alert('Failed to add instruction.'); - } - } - } diff --git a/Francesco.Recipes.World/Views/Shared/_GetInstructions.cshtml b/Francesco.Recipes.World/Views/Shared/_GetInstructions.cshtml index 251b4fc..695bda0 100644 --- a/Francesco.Recipes.World/Views/Shared/_GetInstructions.cshtml +++ b/Francesco.Recipes.World/Views/Shared/_GetInstructions.cshtml @@ -6,7 +6,7 @@
- +
@@ -68,6 +68,32 @@ } } + async function removeInstruction(instructionId) { + if (!confirm('Möchtest du diesen Schritt wirklich löschen?')) return; + + try { + const response = await fetch(`/${recipeId}/RemoveInstruction/${instructionId}`, { + method: 'POST', + headers: { + 'RequestVerificationToken': document.querySelector('input[name="__RequestVerificationToken"]').value + } + }); + + if (response.ok) { + const element = document.getElementById(`instruction-${instructionId}`); + if (element) { + element.remove(); + } + } else { + const error = await response.json(); + alert(error.Error || 'Fehler beim Löschen der Anweisung.'); + } + } catch (error) { + console.error('Fehler beim Löschen:', error); + } + } + + function addInstruction() { const container = document.getElementById('instructions-container'); const newInstructionHtml = `