Exemplo n.º 1
0
        public static IEnumerable <IngredientCategory> GetDefaultCategories()
        {
            List <IngredientCategory> categories = new List <IngredientCategory>
            {
                IngredientCategory.Create("First Category"),
                IngredientCategory.Create("Second Category"),
                IngredientCategory.Create("Third Category"),
                IngredientCategory.Create("4th Category"),
                IngredientCategory.Create("5th Category"),
                IngredientCategory.Create("other-ingredients")
            };

            return(categories);
        }
Exemplo n.º 2
0
        public async Task AddIngredientCustom(Guid recipeId, string categoryName, string measureUnit, string name,
                                              double quantity, double cost, double weight)
        {
            Ingredient ingredient;

            if (!await Exists(name, measureUnit))
            {
                Guid categoryId;
                if (!await _ingredientsCategoryRepository.Exists(categoryName))
                {
                    IngredientCategory igCat = IngredientCategory.Create(categoryName);
                    await _ingredientsCategoryRepository.Add(igCat);

                    categoryId = igCat.Id;
                }
                else
                {
                    categoryId = (await _ingredientsCategoryRepository.GetByName(categoryName)).Id;
                }
                double scale = IngredientsRepository.MapMeasurement["undefined"];
                if (IngredientsRepository.MapMeasurement.ContainsKey(measureUnit))
                {
                    scale = IngredientsRepository.MapMeasurement[measureUnit];
                }

                ingredient = Ingredient.Create(categoryId, name, measureUnit, cost * scale * weight / 10000000);
                await Add(ingredient);
                await UpdateIngredientsCategory(name, await GetSpecificCategory(name));
            }
            else
            {
                if (!categoryName.Equals("other-ingredients"))
                {
                    if (!await _ingredientsCategoryRepository.Exists(categoryName))
                    {
                        IngredientCategory igCat = IngredientCategory.Create(categoryName);
                        await _ingredientsCategoryRepository.Add(igCat);
                    }
                    await UpdateIngredientsCategory(name, (await _ingredientsCategoryRepository.GetByName(categoryName)).Id);
                }
                ingredient = await GetByNameAndMeasure(name, measureUnit);
            }
            await _fridgeRepository.Add(PairItem.Create(ingredient.Id, recipeId, quantity));
        }