Merge develop into feature/Show-ShoppingList-Of-Active-RecipeCard
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
namespace Francesco.Recipes.World.Controller.Favorite
|
||||
{
|
||||
using Francesco.Recipes.World.Constants;
|
||||
using Francesco.Recipes.World.Models;
|
||||
using Francesco.Recipes.World.Repositories.Favorit;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[Route("Favorite")]
|
||||
public class FavoriteController : Controller
|
||||
{
|
||||
private readonly IFavoriteRepository _favoriteRepository;
|
||||
|
||||
public FavoriteController(IFavoriteRepository favoriteRepository)
|
||||
{
|
||||
_favoriteRepository = favoriteRepository;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index(string sortOrder = SortOrders.Newest)
|
||||
{
|
||||
var favoriteRecipes = await _favoriteRepository.GetFavoriteRecipesAsync();
|
||||
|
||||
var sortedRecipes = sortOrder == SortOrders.Oldest
|
||||
? favoriteRecipes.OrderBy(r => r.Favorite.CreatedAt)
|
||||
: favoriteRecipes.OrderByDescending(r => r.Favorite.CreatedAt);
|
||||
|
||||
var viewModel = new FavoriteViewModel
|
||||
{
|
||||
FavoriteRecipes = sortedRecipes,
|
||||
SortOrder = sortOrder,
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,7 +412,7 @@
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,5 +470,50 @@
|
||||
|
||||
return PartialView("_IngredientsPartial", viewModel);
|
||||
}
|
||||
|
||||
// GET: /Recipe/{recipeId}/AdjustableIngredients
|
||||
[HttpGet("{recipeId}/AdjustableIngredients")]
|
||||
public async Task<IActionResult> GetAdjustableIngredients(Guid recipeId)
|
||||
{
|
||||
var recipe = await _recipeRepository.GetRecipeByIdAsync(recipeId);
|
||||
if (recipe == null)
|
||||
{
|
||||
return NotFound("Recipe not found.");
|
||||
}
|
||||
|
||||
return PartialView("_AdjustableIngredientsPartial", recipe);
|
||||
}
|
||||
|
||||
// GET: /Recipe/{recipeId}/Delete
|
||||
[HttpGet("{recipeId}/Delete")]
|
||||
public async Task<IActionResult> Delete(Guid recipeId)
|
||||
{
|
||||
var recipe = await _recipeRepository.GetRecipeByIdAsync(recipeId);
|
||||
if (recipe == null)
|
||||
{
|
||||
return NotFound("Recipe not found.");
|
||||
}
|
||||
|
||||
return View(recipe);
|
||||
}
|
||||
|
||||
// DELETE: /Recipe/{recipeId}/Delete
|
||||
[HttpDelete("{recipeId}/Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(Guid recipeId)
|
||||
{
|
||||
var deleted = await _recipeRepository.DeleteRecipeAsync(recipeId);
|
||||
|
||||
if (deleted)
|
||||
{
|
||||
TempData["SuccessMessage"] = "Rezept wurde erfolgreich gelöscht.";
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
TempData["ErrorMessage"] = "Rezept nicht gefunden oder konnte nicht gelöscht werden.";
|
||||
return RedirectToAction("Details", new { recipeId });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user