示例#1
0
        public static async void Populate(DatabaseContext s)
        {
            var categoryRepo = new IngredientsCategoryRepository(s);
            IEnumerable <IngredientCategory> categories = GetDefaultCategories();

            foreach (var ingredientCategory in categories)
            {
                await categoryRepo.Add(ingredientCategory);
            }
            var fridgeRepos    = new FridgeRepository(s);
            var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos);
            var recipeRepo     = new RecipesRepository(s, fridgeRepos, ingredientRepo);

            Ingredient i1   = Ingredient.Create(categories.First().Id, "i1", "cup", 0.9);
            Ingredient i2   = Ingredient.Create(categories.First().Id, "i2", "piece", 1.9);
            Ingredient i3   = Ingredient.Create(categories.First().Id, "i3", "slice", 0.5);
            Ingredient i4   = Ingredient.Create(categories.First().Id, "i3", "cup", 30);
            User       user = User.Create("xx", true, "*****@*****.**", "sh", "sdsbdk", "sureal");

            var userRepo = new UsersRepository(s);
            await userRepo.Add(user);

            await ingredientRepo.Add(i1);

            await ingredientRepo.Add(i2);

            await ingredientRepo.Add(i3);

            await ingredientRepo.Add(i4);

            Recipe recipe1 = Recipe.Create(user.Id, "r1", "reteta", RecipeStatusType.Approved, 10, 1, KitchenType.Asian);
            Recipe recipe2 = Recipe.Create(user.Id, "r2", "reteta2", RecipeStatusType.Approved, 15, 2, KitchenType.Unspecified);
            await recipeRepo.Add(recipe1);

            await recipeRepo.Add(recipe2);

            await recipeRepo.UpdateAllCosts();

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe1.Id, 2));

            await fridgeRepos.Add(PairItem.Create(i2.Id, recipe1.Id, 4));

            await fridgeRepos.Add(PairItem.Create(i3.Id, recipe1.Id, 1));

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe2.Id, 3));
        }
        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));
        }
示例#3
0
        public static IEnumerable <PairItem> GetPairItems(int count = 1)
        {
            List <PairItem> items = new List <PairItem>
            {
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 1.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 5.3f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 8.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 9.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 3.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 2.1f)
            };

            if (0 >= count)
            {
                throw new IndexOutOfRangeException("Null or negative count [in BaseIntegrationTest class]");
            }
            if (items.Count < count)
            {
                throw new IndexOutOfRangeException("Not enough users in Pair Item List [in BaseIntegrationTest class]");
            }
            return(items.Take(count));
        }