Revert "add CategoryController with endpoints"

This reverts commit 36bca4d658.
This commit is contained in:
franc
2025-04-08 15:23:57 +02:00
parent 36bca4d658
commit 928743303c
24 changed files with 142 additions and 1535 deletions
@@ -1,12 +0,0 @@
namespace Francesco.Recipes.World.Views.Category
{
using Francesco.Recipes.World.Models.BackendModels.Category;
using Francesco.Recipes.World.Models.BackendModels.Recipe;
public class CategoryRecipesViewModel
{
public Category Category { get; set; } = new ();
public IEnumerable<Recipe> Recipes { get; set; } = new List<Recipe>();
}
}
@@ -1,59 +0,0 @@
@model Francesco.Recipes.World.Models.BackendModels.Recipe.Recipe
@{
ViewData["Title"] = "Add Instructions";
}
<h1>Add Instructions to @Model.Name</h1>
<div class="instructions-list">
<h3>Existing Instructions</h3>
<ul>
@foreach (var instruction in Model.Instructions.OrderBy(i => i.Number))
{
<li>@instruction.Number. @instruction.Description</li>
}
</ul>
</div>
<div class="add-instruction-form">
<h3>Add New Instruction</h3>
<form id="instruction-form" method="post" asp-action="AddInstruction" asp-controller="Recipe">
<input type="hidden" name="recipeId" value="@Model.Id" />
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" name="description" required />
</div>
<div class="form-group">
<label for="number">Number</label>
<input type="number" class="form-control" id="number" name="number" required min="1" />
</div>
<button type="submit" class="btn btn-primary" onclick="addInstructionToRecipe()">Add Instruction</button>
</form>
</div>
@section Scripts {
<script>
async function addInstructionToRecipe() {
var form = document.getElementById('instruction-form');
var recipeId = form.querySelector('input[name="recipeId"]').value;
var description = form.querySelector('input[name="description"]').value;
var number = form.querySelector('input[name="number"]').value;
var response = await fetch('/Recipe/' + recipeId + '/AddInstruction', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ recipeId: recipeId, description: description, number: number })
});
if (response.ok) {
location.reload();
} else {
alert('Failed to add instruction.');
}
}
</script>
}
@@ -1,27 +1,29 @@
@{
ViewData["Title"] = "Add or Create Ingredient to Recipe";
ViewData["Title"] = "Add or Create Ingredient to Recipe";
}
<h2>@ViewData["Title"]</h2>
<form asp-action="AddOrCreateIngredient" method="post">
<input type="hidden" id="RecipeId" name="recipeId" value="@ViewBag.RecipeId" />
<div class="form-group">
<label for="IngredientName" class="control-label">Ingredient Name</label>
<input type="text" id="IngredientName" name="ingredientName" class="form-control" />
</div>
<div class="form-group">
<label for="Quantity" class="control-label">Quantity</label>
<input type="number" id="Quantity" name="quantity" class="form-control" />
</div>
<div class="form-group">
<label for="UnitId" class="control-label">Unit</label>
<select id="UnitId" name="unitId" class="form-control" asp-items="ViewBag.Units"></select>
</div>
<button type="submit" class="btn btn-primary">Add Ingredient</button>
<div class="form-group">
<label for="RecipeId" class="control-label">Recipe Id</label>
<input type="text" id="RecipeId" name="recipeId" class="form-control" />
</div>
<div class="form-group">
<label for="IngredientName" class="control-label">Ingredient Name</label>
<input type="text" id="IngredientName" name="ingredientName" class="form-control" />
</div>
<div class="form-group">
<label for="Quantity" class="control-label">Quantity</label>
<input type="number" id="Quantity" name="quantity" class="form-control" />
</div>
<div class="form-group">
<label for="UnitId" class="control-label">Unit</label>
<select id="UnitId" name="unitId" class="form-control" asp-items="ViewBag.Units"></select>
</div>
<button type="submit" class="btn btn-primary">Add Ingredient</button>
</form>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
<partial name="_ValidationScriptsPartial" />
}
@@ -1,98 +0,0 @@
@model IEnumerable<Francesco.Recipes.World.Views.Category.CategoryRecipesViewModel>
@{
ViewData["Title"] = "Category Recipes";
}
<h1>Category Recipes</h1>
@foreach (var categoryRecipes in Model)
{
<div class="category-section">
<h2>@categoryRecipes.Category.Name</h2>
<a asp-action="Create" asp-route-categoryId="@categoryRecipes.Category.Id" class="btn btn-primary">Rezept erstellen</a>
<div class="recipes">
@foreach (var recipe in categoryRecipes.Recipes)
{
<div class="recipe-card">
<div class="recipe-image">
@if (recipe.MediaFiles.Any() && recipe.MediaFiles.First().Data != null)
{
var mediaFile = recipe.MediaFiles.First();
if (mediaFile.Data != null)
{
<img src="data:@mediaFile.MimeType;base64,@Convert.ToBase64String(mediaFile.Data)" alt="@recipe.Name" class="img-fluid" />
}
}
</div>
<div class="recipe-info">
<h3>@recipe.Name</h3>
<p>@recipe.Description</p>
<p><strong>Difficulty:</strong> @recipe.Difficulty</p>
<p><strong>Servings:</strong> @recipe.Servings</p>
<p><strong>Preparation Time:</strong> @recipe.PreparationTime</p>
<p><strong>Cooking Time:</strong> @recipe.CookingTime</p>
<div class="recipe-favorite">
@if (recipe.IsFavorite)
{
<form method="post" asp-action="RemoveFavorite" asp-controller="Recipe">
<input type="hidden" name="recipeId" value="@recipe.Id" />
<button type="submit" class="btn btn-danger">Remove from Favorites</button>
</form>
}
else
{
<form method="post" asp-action="AddFavorite" asp-controller="Recipe">
<input type="hidden" name="recipeId" value="@recipe.Id" />
<button type="submit" class="btn btn-primary">Add to Favorites</button>
</form>
}
</div>
</div>
</div>
}
<div class="recipe-card add-recipe-card">
<a asp-action="Create" asp-route-categoryId="@categoryRecipes.Category.Id" class="btn btn-primary">Rezept hinzufügen</a>
</div>
</div>
</div>
}
<style>
.category-section {
margin-bottom: 2rem;
}
.recipes {
display: flex;
flex-wrap: wrap;
}
.recipe-card {
width: 200px;
margin: 1rem;
padding: 1rem;
border: 1px solid #ccc;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.recipe-image img {
width: 100%;
height: auto;
border-radius: 8px;
}
.recipe-info {
margin-top: 1rem;
}
.add-recipe-card {
display: flex;
align-items: center;
justify-content: center;
background-color: #f8f8f8;
border: 2px dashed #ccc;
}
</style>
@@ -1,53 +1,45 @@
@model Francesco.Recipes.World.Models.BackendModels.Recipe.Recipe
@using Francesco.Recipes.World.Models.BackendModels.Recipe
@{
ViewData["Title"] = "Create Recipe";
ViewData["Title"] = "Create Recipe";
}
<h1>Create Recipe</h1>
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Difficulty"></label>
<select asp-for="Difficulty" class="form-control">
<option value="">Select Difficulty</option>
@foreach (var difficulty in Enum.GetValues(typeof(Difficulty)))
{
<option value="@difficulty">@difficulty</option>
}
</select>
<span asp-validation-for="Difficulty" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Servings"></label>
<input asp-for="Servings" class="form-control" />
<span asp-validation-for="Servings" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PreparationTime"></label>
<input asp-for="PreparationTime" class="form-control" />
<span asp-validation-for="PreparationTime" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CookingTime"></label>
<input asp-for="CookingTime" class="form-control" />
<span asp-validation-for="CookingTime" class="text-danger"></span>
</div>
<div class="form-group">
<label for="photo">Photo</label>
<input type="file" name="photo" class="form-control" />
</div>
<button type="submit" class="btn btn-primary">Create</button>
<form asp-action="Create" method="post">
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<textarea asp-for="Description" class="form-control"></textarea>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Difficulty" class="control-label"></label>
<select asp-for="Difficulty" class="form-control" asp-items="Html.GetEnumSelectList<Difficulty>()"></select>
<span asp-validation-for="Difficulty" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Servings" class="control-label"></label>
<input asp-for="Servings" class="form-control" />
<span asp-validation-for="Servings" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PreparationTime" class="control-label"></label>
<input asp-for="PreparationTime" class="form-control" placeholder="hh:mm:ss" />
<span asp-validation-for="PreparationTime" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CookingTime" class="control-label"></label>
<input asp-for="CookingTime" class="form-control" placeholder="hh:mm:ss" />
<span asp-validation-for="CookingTime" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
@section Scripts {
@@ -1,68 +0,0 @@
@model Francesco.Recipes.World.Models.BackendModels.Recipe.Recipe
@{
ViewData["Title"] = "Recipe Details";
}
<h1>@Model.Name</h1>
<div class="recipe-details">
<div class="recipe-image">
@if (Model.MediaFiles.Any() && Model.MediaFiles.First().Data != null)
{
var mediaFile = Model.MediaFiles.First();
if (mediaFile.Data != null)
{
<img src="data:@mediaFile.MimeType;base64,@Convert.ToBase64String(mediaFile.Data)" alt="@Model.Name" class="img-fluid" />
}
}
</div>
<div class="recipe-info">
<p><strong>Description:</strong> @Model.Description</p>
<p><strong>Difficulty:</strong> @Model.Difficulty</p>
<p><strong>Servings:</strong> @Model.Servings</p>
<p><strong>Preparation Time:</strong> @Model.PreparationTime</p>
<p><strong>Cooking Time:</strong> @Model.CookingTime</p>
</div>
<div class="recipe-ingredients">
<h3>Ingredients</h3>
<form id="ingredient-form">
<ul id="ingredient-list">
@foreach (var ingredient in Model.RecipeIngredients)
{
<li id="ingredient-@ingredient.Id">
<input type="checkbox" name="ingredientIds" value="@ingredient.Id" />
@ingredient.Ingredient.Name - @ingredient.Quantity @(ingredient.Unit != null ? ingredient.Unit.Symbol : string.Empty)
</li>
}
</ul>
<button type="button" class="btn btn-primary" onclick="addSelectedIngredientsToShoppingList()">Add Selected to Shopping List</button>
</form>
</div>
</div>
@section Scripts {
<script>
async function addSelectedIngredientsToShoppingList() {
var form = document.getElementById('ingredient-form');
var formData = new FormData(form);
var selectedIngredientIds = formData.getAll('ingredientIds');
var response = await fetch('/ShoppingList/CreateOrAddIngredients', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ recipeId: '@Model.Id', ingredientIds: selectedIngredientIds })
});
if (response.ok) {
var result = await response.json();
localStorage.setItem('shoppingListId', result.shoppingListId);
alert('Shopping list updated.');
} else {
alert('Failed to update shopping list.');
}
}
</script>
}
@@ -1,72 +1,42 @@
@using Francesco.Recipes.World.Models.BackendModels.Recipe
@model Francesco.Recipes.World.Views.Recipe.FilterByDifficultyViewModel
@model Francesco.Recipes.World.Views.Recipe.FilterByDifficultyViewModel
@using Francesco.Recipes.World.Models.BackendModels.Recipe
<h1>Rezepte nach Schwierigkeitsgrad</h1>
@{
ViewData["Title"] = "Filter Recipes by Difficulty";
}
<div class="mb-3">
<a asp-controller="Recipe" asp-action="Create" class="btn btn-primary">Neues Rezept erstellen</a>
</div>
<h1>Filter Recipes by Difficulty</h1>
<div class="row mb-4">
<div class="col-md-6">
<form asp-controller="Recipe" asp-action="FilterByDifficulty" method="get" id="filterForm">
<div class="form-group">
<label asp-for="SelectedDifficulty" class="form-label">Schwierigkeitsgrad</label>
<select asp-for="SelectedDifficulty" asp-items="Html.GetEnumSelectList<Difficulty>()" class="form-select" onchange="submitForm()">
<option value="">Alle Schwierigkeitsgrade</option>
</select>
</div>
</form>
<form asp-action="FilterByDifficulty" method="get" id="filterForm">
<div class="form-group">
<label asp-for="SelectedDifficulty" class="control-label"></label>
<select asp-for="SelectedDifficulty" class="form-control" asp-items="Html.GetEnumSelectList<Difficulty>()" class="form-select" onchange="submitForm()">
<option value="">All Difficulties</option>
</select>
<span asp-validation-for="SelectedDifficulty" class="text-danger"></span>
</div>
</form>
</div>
</div>
<div class="row">
@if (Model?.Recipes != null && Model.Recipes.Any())
{
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Beschreibung</th>
<th>Schwierigkeitsgrad</th>
<th>Portionen</th>
<th>Zubereitungszeit</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
@foreach (var recipe in Model.Recipes)
{
<tr>
<td>@recipe.Name</td>
<td>@(recipe.Description?.Length > 100 ? recipe.Description.Substring(0, 100) + "..." : recipe.Description)</td>
<td>@recipe.?Difficulty</td>
<td>@recipe.Servings</td>
<td>@($"{recipe.PreparationTime.TotalMinutes} Min.")</td>
<td>
<a asp-controller="Recipe" asp-action="Details" asp-route-id="@recipe.Id" class="btn btn-sm btn-info">Details</a>
<a asp-controller="Recipe" asp-action="Edit" asp-route-id="@recipe.Id" class="btn btn-sm btn-primary">Bearbeiten</a>
</td>
</tr>
}
</tbody>
</table>
</div>
}
else
{
<div class="col-12">
<p>Keine Rezepte gefunden.</p>
</div>
}
</div>
@if (Model.Recipes != null && Model.Recipes.Any())
{
<h2>Filtered Recipes</h2>
<ul>
@foreach (var recipe in Model.Recipes)
{
<li>@recipe.Name - @recipe.Difficulty.</li>
}
</ul>
}
else
{
<p>No recipes found for the selected difficulty.</p>
}
@section Scripts {
<script>
function submitForm() {
document.getElementById('filterForm').submit();
}
</script>
<script>
function submitForm() {
document.getElementById('filterForm').submit();
}
</script>
@await Html.PartialAsync("_ValidationScriptsPartial")
}
@@ -7,6 +7,6 @@
{
public Difficulty? SelectedDifficulty { get; set; }
public IReadOnlyCollection<Recipe> Recipes { get; set; } = new List<Recipe>();
public List<Recipe> Recipes { get; set; } = new List<Recipe>();
}
}
@@ -1,43 +0,0 @@
@model IEnumerable<Francesco.Recipes.World.Models.BackendModels.RecipeIngredient.RecipeIngredient>
<div class="recipe-ingredients">
<h3>Zutaten</h3>
<form id="ingredient-form">
<ul id="ingredient-list">
@foreach (var ingredient in Model)
{
<li id="ingredient-@ingredient.Id">
<input type="checkbox" name="ingredientIds" value="@ingredient.Id" />
@ingredient.Ingredient.Name - @ingredient.Quantity @ingredient.Unit.Symbol
</li>
}
</ul>
<button type="button" class="btn btn-primary" onclick="addSelectedIngredientsToShoppingList()">Ausgewählte zur Einkaufsliste hinzufügen</button>
</form>
</div>
@section Scripts {
<script>
function addSelectedIngredientsToShoppingList() {
var form = document.getElementById('ingredient-form');
var formData = new FormData(form);
var selectedIngredientIds = formData.getAll('ingredientIds');
fetch('/ShoppingList/AddSelectedIngredients', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ ingredientIds: selectedIngredientIds })
}).then(response => {
if (response.ok) {
alert('Ausgewählte Zutaten wurden zur Einkaufsliste hinzugefügt.');
} else {
alert('Fehler beim Hinzufügen der ausgewählten Zutaten zur Einkaufsliste.');
}
}).catch(error => {
alert('Ein Fehler ist aufgetreten: ' + error.message);
});
}
</script>
}
@@ -1,56 +0,0 @@
@model Francesco.Recipes.World.Models.BackendModels.Shoppinglist.ShoppingList
@using Francesco.Recipes.World.Models.BackendModels.RecipeShoppingList
@using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient
@using Francesco.Recipes.World.Models.BackendModels.Recipe
@{
ViewData["Title"] = "Einkaufsliste Details";
}
<h2>Einkaufsliste Details</h2>
@if (TempData["SuccessMessage"] != null)
{
<div class="alert alert-success">
@TempData["SuccessMessage"]
</div>
}
<div>
<h4>Einkaufsliste</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
ID
</dt>
<dd class="col-sm-10">
@Model.Id
</dd>
</dl>
</div>
<h4>Rezepte</h4>
<table class="table">
<thead>
<tr>
<th>Rezeptname</th>
<th>Zutaten</th>
</tr>
</thead>
<tbody>
@foreach (var recipeShoppingList in Model.RecipeShoppingList)
{
<tr>
<td>@recipeShoppingList.Recipe.Name</td>
<td>
<ul>
@foreach (var ingredient in recipeShoppingList.SelectedIngredients)
{
<li>@ingredient.RecipeIngredient.Ingredient.Name - @ingredient.RecipeIngredient.Quantity @ingredient.RecipeIngredient.Unit.Name</li>
}
</ul>
</td>
</tr>
}
</tbody>
</table>