public async Task <IActionResult> CreateTest([FromBody] RecipeCreateView recipe) { if (ModelState.IsValid) { var ingredients = ingredientsService.GetAllByName(recipe.Ingredients).Select(x => x.Name).ToList(); if (recipe.Ingredients.Count != ingredients.Count) { var diff = recipe.Ingredients.Except(ingredients).ToList(); foreach (var ing in diff) { var newIng = new Ingredient(); newIng.Name = ing; ingredientsService.Create(newIng); } } var ingredientsDB = ingredientsService.GetAllByName(recipe.Ingredients); var recipeToDb = recipe.ToRecipeCreate(); var currentUser = await userManager.GetUserAsync(User); recipeService.Create(recipeToDb, ingredientsDB, currentUser.Id); return(Ok()); } return(View(recipe)); }
public static Recipe ToRecipeCreate(this RecipeCreateView recipe) { return(new Recipe { Title = recipe.Title, Description = recipe.Description, Preparation = recipe.Preparation, Price = recipe.Price }); }
public IActionResult CreateTest() { var recipe = new RecipeCreateView(); return(View(recipe)); }