Exemplo n.º 1
0
        public async Task <IEnumerable <Recipe> > GetByBrands(List <Product> products, Task <IEnumerable <Recipe> > recipes)
        {
            IEnumerable <Recipe> recipesWithIngredients = Enumerable.Empty <Recipe>();

            foreach (Recipe recipe in await recipes)
            {
                bool containsIngredient = false;
                IEnumerable <Ingredient> ingredients = await _ingredientsRepository.GetByRecipe(recipe.Id);

                foreach (Ingredient ingredient in ingredients)
                {
                    ProductStore productStore = await _productStoresRepository.GetById(ingredient.ProductStoreId);

                    foreach (Product product in products)
                    {
                        if (product.Id == productStore.ProductId)
                        {
                            containsIngredient = true;
                            continue;
                        }
                    }
                }

                if (containsIngredient)
                {
                    recipesWithIngredients.Append(recipe);
                }
            }


            return(recipesWithIngredients);
        }
Exemplo n.º 2
0
        public async Task UpdateCost(Guid ingredientId)
        {
            Ingredient   ingredient   = _databaseContext.Ingredients.Where(i => i.Id == ingredientId).FirstOrDefault();
            ProductStore productStore = await _productStoresRepository.GetById(ingredient.ProductStoreId);

            double newCost = ingredient.NrOfProductsNecessary * productStore.Price;

            ingredient.Update(ingredient.RecipeId, ingredient.ProductStoreId, ingredient.Name, ingredient.Quantity, newCost, ingredient.UnitOfMeasurement, ingredient.NrOfProductsNecessary);
            _databaseContext.SaveChanges();
        }