Exemplo n.º 1
0
        public void Add(MealDTO mealDto)
        {
            var meal = new Meal
            {
                Name        = mealDto.Name,
                NameForeign = mealDto.NameForeign
            };

            _mealRepository.Add(meal, mealDto.ImageBase64);

            var ingredients = new List <Ingredient>();

            foreach (var item in mealDto.Ingredients)
            {
                ingredients.Add(new Ingredient
                {
                    Name        = item.Name,
                    NameForeign = item.NameForeign
                });
            }
            _ingredientRepository.Add(ingredients);

            var allergens = new List <Allergen>();

            foreach (var item in mealDto.Allergens)
            {
                allergens.Add(new Allergen
                {
                    Name        = item.Name,
                    NameForeign = item.NameForeign
                });
            }
            _allergenRepository.Add(allergens);

            var mealIngredients = new List <MealIngredient>();

            foreach (var item in ingredients)
            {
                mealIngredients.Add(new MealIngredient
                {
                    MealId       = meal.Id,
                    IngredientId = item.Id
                });
            }
            _ingredientRepository.AddMealIngredients(mealIngredients);

            var mealAllergens = new List <MealAllergen>();

            foreach (var item in allergens)
            {
                mealAllergens.Add(new MealAllergen
                {
                    MealId     = meal.Id,
                    AllergenId = item.Id
                });
            }
            _allergenRepository.AddMealAllergens(mealAllergens);
        }