From 27d4fd5368a2bcfddd4f937064eed42ad676da97 Mon Sep 17 00:00:00 2001 From: franc Date: Wed, 7 May 2025 10:03:02 +0200 Subject: [PATCH] Solve Thread of mergeRequest --- .../Controller/Recipe/RecipeController.cs | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/Francesco.Recipes.World/Controller/Recipe/RecipeController.cs b/Francesco.Recipes.World/Controller/Recipe/RecipeController.cs index d9b6996..e19eea3 100644 --- a/Francesco.Recipes.World/Controller/Recipe/RecipeController.cs +++ b/Francesco.Recipes.World/Controller/Recipe/RecipeController.cs @@ -55,6 +55,11 @@ [HttpGet("{recipeId}/AddOrCreateIngredient")] public async Task AddOrCreateIngredient(Guid recipeId) { + if (recipeId == Guid.Empty) + { + return BadRequest("Recipe ID cannot be empty."); + } + var units = await _unitRepository.GetAllUnitsAsync(); var recipeIngredients = await _ingredientRepository.GetIngredientsByRecipeIdAsync(recipeId); var ingredients = recipeIngredients.Select(ri => ri.Ingredient).ToList(); @@ -278,28 +283,7 @@ catch (Exception ex) { await transaction.RollbackAsync(); - - 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(), - Units = units.ToList(), - }; - } - else - { - model.IngredientViewModel.Units = units.ToList(); - } - - model.CategoryName = category?.Name ?? string.Empty; - return View(model); + return BadRequest(ex.Message); } } @@ -416,7 +400,7 @@ await _instructionRepository.CreateInstructionAsync(recipeId, description, image); var recipe = await _recipeRepository.GetRecipeByIdAsync(recipeId); - var instructions = recipe?.Instructions?.ToList() ?? new List(); + var instructions = recipe?.Instructions?.ToList() ?? new List(); var viewModel = new InstructionViewModel { @@ -428,7 +412,7 @@ } catch (Exception ex) { - return BadRequest(ex.Message); + return BadRequest(ex.Message); } }