All thread resolved
This commit is contained in:
@@ -45,7 +45,7 @@
|
||||
}
|
||||
|
||||
[HttpPost("ReplaceInstructionImage")]
|
||||
[ValidateAntiForgeryToken]
|
||||
[AutoValidateAntiforgeryToken]
|
||||
public async Task<IActionResult> ReplaceInstructionImage(Guid instructionId, Guid mediaFileIdToReplace, IFormFile? newPhoto)
|
||||
{
|
||||
if (newPhoto is null)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
using Francesco.Recipes.World.Models;
|
||||
using Francesco.Recipes.World.Repositories.ShoppingList;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public class ShoppingListController : Controller
|
||||
{
|
||||
@@ -21,17 +20,17 @@
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> CreateOrAddIngredients([FromBody] CreateOrAddIngredientRequestModel request)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (request == null || request.IngredientIds == null || !request.IngredientIds.Any())
|
||||
{
|
||||
return BadRequest("No ingredients provided.");
|
||||
}
|
||||
|
||||
await _shoppingListRepository.AddIngredientsToShoppingListAsync(request.RecipeId, request.IngredientIds);
|
||||
|
||||
var shoppingList = await _context.ShoppingLists
|
||||
.Include(sl => sl.RecipeShoppingList)
|
||||
.ThenInclude(rsl => rsl.Recipe)
|
||||
.FirstOrDefaultAsync(sl => sl.RecipeShoppingList.Any(rsl => rsl.Recipe.Id == request.RecipeId));
|
||||
var shoppingList = await _shoppingListRepository.AddIngredientsToShoppingListAsync(request.RecipeId, request.IngredientIds);
|
||||
|
||||
if (shoppingList == null)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ using Francesco.Recipes.World.Repositories.MediaFile;
|
||||
using Francesco.Recipes.World.Repositories.Recipe;
|
||||
using Francesco.Recipes.World.Repositories.ShoppingList;
|
||||
using Francesco.Recipes.World.Repositories.Unit;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
{
|
||||
await RemoveExistingMediaAsync(recipe, "image/");
|
||||
}
|
||||
else if (isVideo)
|
||||
else
|
||||
{
|
||||
await RemoveExistingMediaAsync(recipe, "video/");
|
||||
}
|
||||
|
||||
@@ -52,9 +52,11 @@
|
||||
}
|
||||
|
||||
var ingredients = await _ingredientRepository.GetIngredientsByNameAsync(ingredientName);
|
||||
var exactMatch = ingredients
|
||||
.FirstOrDefault(i => i.Name.Equals(ingredientName, StringComparison.OrdinalIgnoreCase));
|
||||
Ingredient ingredient;
|
||||
|
||||
if (!ingredients.Any())
|
||||
if (exactMatch == null)
|
||||
{
|
||||
ingredient = new Ingredient
|
||||
{
|
||||
@@ -66,7 +68,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
ingredient = ingredients.First();
|
||||
ingredient = exactMatch;
|
||||
}
|
||||
|
||||
var existingEntry = await _context.RecipeIngredients
|
||||
@@ -83,6 +85,7 @@
|
||||
Unit = unit,
|
||||
Quantity = quantity,
|
||||
};
|
||||
|
||||
_context.Add(recipeIngredient);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
{
|
||||
using Francesco.Recipes.World.Models.BackendModels.IngredientShoppingList;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Recipe;
|
||||
using Francesco.Recipes.World.Models.BackendModels.Shoppinglist;
|
||||
|
||||
public interface IShoppingListRepository
|
||||
{
|
||||
Task AddIngredientsToShoppingListAsync(Guid shoppingListId, List<Guid> ingredientIds);
|
||||
Task<ShoppingList> AddIngredientsToShoppingListAsync(Guid recipeId, List<Guid> ingredientIds);
|
||||
|
||||
Task<IEnumerable<RecipeIngredientShoppingList>> GetIngredientsOfRecipeInListAsync(Guid shoppingListRecipeId);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task AddIngredientsToShoppingListAsync(Guid recipeId, List<Guid> ingredientIds)
|
||||
public async Task<ShoppingList> AddIngredientsToShoppingListAsync(Guid recipeId, List<Guid> ingredientIds)
|
||||
{
|
||||
if (ingredientIds == null || !ingredientIds.Any())
|
||||
{
|
||||
@@ -29,13 +29,12 @@
|
||||
|
||||
if (recipe == null)
|
||||
{
|
||||
throw new Exception("Rezept nicht gefunden.");
|
||||
throw new Exception("Recipe not found.");
|
||||
}
|
||||
|
||||
var shoppingList = await _context.ShoppingLists
|
||||
.Include(sl => sl.RecipeShoppingList)
|
||||
.ThenInclude(rsl => rsl.SelectedIngredients)
|
||||
.ThenInclude(si => si.RecipeIngredient)
|
||||
.Include(sl => sl.RecipeShoppingList)
|
||||
.ThenInclude(rsl => rsl.Recipe)
|
||||
.FirstOrDefaultAsync(sl => sl.RecipeShoppingList.Any(rsl => rsl.Recipe.Id == recipeId));
|
||||
@@ -46,7 +45,7 @@
|
||||
|
||||
if (!recipeIngredients.Any())
|
||||
{
|
||||
throw new Exception("Keine gültigen Zutaten gefunden.");
|
||||
throw new Exception("No valid ingredients found.");
|
||||
}
|
||||
|
||||
if (shoppingList == null)
|
||||
@@ -55,7 +54,6 @@
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
ModifiedAt = null,
|
||||
RecipeShoppingList = new List<RecipeShoppingList>(),
|
||||
};
|
||||
|
||||
@@ -93,10 +91,7 @@
|
||||
|
||||
foreach (var ri in recipeIngredients)
|
||||
{
|
||||
var alreadyExists = existingRecipeList.SelectedIngredients
|
||||
.Any(si => si.RecipeIngredient.Id == ri.Id);
|
||||
|
||||
if (!alreadyExists)
|
||||
if (!existingRecipeList.SelectedIngredients.Any(si => si.RecipeIngredient.Id == ri.Id))
|
||||
{
|
||||
existingRecipeList.SelectedIngredients.Add(new RecipeIngredientShoppingList
|
||||
{
|
||||
@@ -109,6 +104,9 @@
|
||||
|
||||
shoppingList.ModifiedAt = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return shoppingList;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RecipeIngredientShoppingList>> GetIngredientsOfRecipeInListAsync(Guid shoppingListRecipeId)
|
||||
@@ -153,8 +151,6 @@
|
||||
public async Task DeleteShoppingListAsync(Guid shoppingListId)
|
||||
{
|
||||
var list = await _context.ShoppingLists
|
||||
.Include(sl => sl.RecipeShoppingList)
|
||||
.ThenInclude(r => r.SelectedIngredients)
|
||||
.FirstOrDefaultAsync(sl => sl.Id == shoppingListId);
|
||||
|
||||
if (list != null)
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.4/dist/htmx.js" integrity="sha384-oeUn82QNXPuVkGCkcrInrS1twIxKhkZiFfr2TdiuObZ3n3yIeMiqcRzkIcguaof1" crossorigin="anonymous"></script>
|
||||
@await RenderSectionAsync("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user