Solve Thread of mergeRequest

This commit is contained in:
franc
2025-05-07 10:03:02 +02:00
parent 7f6998c2de
commit 27d4fd5368
@@ -55,6 +55,11 @@
[HttpGet("{recipeId}/AddOrCreateIngredient")] [HttpGet("{recipeId}/AddOrCreateIngredient")]
public async Task<IActionResult> AddOrCreateIngredient(Guid recipeId) public async Task<IActionResult> AddOrCreateIngredient(Guid recipeId)
{ {
if (recipeId == Guid.Empty)
{
return BadRequest("Recipe ID cannot be empty.");
}
var units = await _unitRepository.GetAllUnitsAsync(); var units = await _unitRepository.GetAllUnitsAsync();
var recipeIngredients = await _ingredientRepository.GetIngredientsByRecipeIdAsync(recipeId); var recipeIngredients = await _ingredientRepository.GetIngredientsByRecipeIdAsync(recipeId);
var ingredients = recipeIngredients.Select(ri => ri.Ingredient).ToList(); var ingredients = recipeIngredients.Select(ri => ri.Ingredient).ToList();
@@ -278,28 +283,7 @@
catch (Exception ex) catch (Exception ex)
{ {
await transaction.RollbackAsync(); await transaction.RollbackAsync();
return BadRequest(ex.Message);
ModelState.AddModelError(string.Empty, $"Ein Fehler ist aufgetreten beim Erstellen des Rezepts: {ex.Message}");
var category = await _categoryRepository.GetCategoryByIdAsync(categoryId);
var units = await _unitRepository.GetAllUnitsAsync();
if (model.IngredientViewModel == null)
{
model.IngredientViewModel = new IngredientViewModel
{
RecipeId = Guid.Empty,
Ingredients = new List<Models.BackendModels.Ingredient.Ingredient>(),
Units = units.ToList(),
};
}
else
{
model.IngredientViewModel.Units = units.ToList();
}
model.CategoryName = category?.Name ?? string.Empty;
return View(model);
} }
} }
@@ -416,7 +400,7 @@
await _instructionRepository.CreateInstructionAsync(recipeId, description, image); await _instructionRepository.CreateInstructionAsync(recipeId, description, image);
var recipe = await _recipeRepository.GetRecipeByIdAsync(recipeId); var recipe = await _recipeRepository.GetRecipeByIdAsync(recipeId);
var instructions = recipe?.Instructions?.ToList() ?? new List<Models.BackendModels.Instruction.Instruction>(); var instructions = recipe?.Instructions?.ToList() ?? new List<Instruction>();
var viewModel = new InstructionViewModel var viewModel = new InstructionViewModel
{ {
@@ -428,7 +412,7 @@
} }
catch (Exception ex) catch (Exception ex)
{ {
return BadRequest(ex.Message); return BadRequest(ex.Message);
} }
} }