Example #1
0
        public async Task <List <DishesView> > GetListDishes()
        {
            var dishDb = await _dishRepository.GetDishes();

            var dishModel = new List <DishesView>();

            foreach (var item in dishDb)
            {
                var dish = new DishesView();
                dish.Id          = item.Id;
                dish.Name        = item.Name;
                dish.UpdatedOn   = item.UpdatedOn;
                dish.Ingredients = new List <DishIngredientsView>();
                var disheIngredients = await _dishesIngredientsRepository.GetDishIngredientsByDishesId(item.Id);

                foreach (var item2 in disheIngredients)
                {
                    var ingredient = await _ingredientsRepository.GetIngredientsById(item2.IngredientId);

                    foreach (var item3 in ingredient)
                    {
                        var ingredientList = new DishIngredientsView()
                        {
                            IngredientId = item2.IngredientId,
                            Name         = item3.Name,
                        };

                        dish.Ingredients.Add(ingredientList);
                    }
                }
                var dishWithParentId = await _dishRepository.GetDishByParentId(item.ParentId);

                if (dishWithParentId != null)
                {
                    foreach (var item4 in dishWithParentId)
                    {
                        var dishesByIngredients = await _dishesIngredientsRepository.GetDishIngredientsByDishesId(item4.Id);

                        foreach (var item5 in dishesByIngredients)
                        {
                            var ingredientByParent = await _ingredientsRepository.GetIngredientsById(item5.IngredientId);

                            {
                                foreach (var item6 in ingredientByParent)
                                {
                                    var ingredientList = new DishIngredientsView();
                                    ingredientList.IngredientId = item5.IngredientId;
                                    ingredientList.Name         = item6.Name;
                                    dish.Ingredients.Add(ingredientList);
                                }
                            }
                        }
                    }
                }
                dishModel.Add(dish);
            }
            return(dishModel);
        }