Example #1
0
        public JsonResult EditRecipeIngredient(EditIngredientViewModel model)
        {
            bool isNewIngredient    = false;
            var  existingIngredient = _recipeService.GetIngredientByName(model.IngredientName);

            if (existingIngredient == null)
            {
                isNewIngredient    = true;
                existingIngredient = _recipeService.AddIngredient(model.IngredientName);
            }

            var recipeIngredientToAdd = _recipeService.AddRecipeIngredient(model.RecipeId, model.Measurement, model.UnitOfMeasurement, existingIngredient.Id);

            return(Json(new
            {
                RecipeId = recipeIngredientToAdd.RecipeId,
                Measurement = recipeIngredientToAdd.Measurement,
                UnitOfMeasurement = recipeIngredientToAdd.UnitOfMeasurement,
                IngredientId = recipeIngredientToAdd.IngredientId,
                IngredientName = model.IngredientName,
                IsNewIngredient = isNewIngredient
            }));
        }