예제 #1
0
        public void AddIngredientToRecipe(Recipe recipe, string ingredientName, string denomination, double amount)
        {
            var ingred = WorkingUnit.Ingredients.GetAll().SingleOrDefault(x => string.Equals(x.Name, ingredientName, StringComparison.OrdinalIgnoreCase) &&
                                                                          string.Equals(x.Denomination, denomination, StringComparison.OrdinalIgnoreCase));

            if (ingred == null)
            {
                ingred = new Ingredient {
                    Id = Guid.NewGuid().ToString(), Name = ingredientName, Denomination = denomination
                };
                WorkingUnit.Ingredients.Add(ingred);
            }
            var ingDetail = new IngredientDetail()
            {
                Ingredient = ingred, Amount = amount
            };

            var checkerDetail = recipe.Ingredients.SingleOrDefault(x => x.Ingredient == ingDetail.Ingredient);

            if (checkerDetail != null)
            {
                checkerDetail.Amount += ingDetail.Amount;
                recipe.IngIdAndAmount[checkerDetail.Ingredient.Id] += amount;
            }
            else
            {
                recipe.Ingredients.Add(ingDetail);
                recipe.IngIdAndAmount.Add(ingDetail.Ingredient.Id, ingDetail.Amount);
            }
            WorkingUnit.Save();
        }
예제 #2
0
        public void SetCategoryInRecipe(Category category, Recipe recipe)
        {
            var retrieved = WorkingUnit.Recipes.GetAll().SingleOrDefault(x => x.CategoryId == recipe.CategoryId);

            if (retrieved != null)
            {
                Console.WriteLine($"Recipe {recipe.Name} is already in category");
                return;
            }
            else
            {
                recipe.CategoryId = category.Id;
                recipe.Category   = category;
                WorkingUnit.Save();
            }
        }
예제 #3
0
        public void CreateRecipe(Recipe recipe)
        {
            var checker = WorkingUnit.Recipes.GetAll().SingleOrDefault(x => string.Equals(x.Name, recipe.Name, StringComparison.OrdinalIgnoreCase));

            if (checker != null)
            {
                Console.WriteLine($"Recipe {checker.Name} : {checker.Id} already exists");
                return;
            }
            if (string.IsNullOrEmpty(recipe.Id))
            {
                recipe.Id = Guid.NewGuid().ToString();
            }
            WorkingUnit.Recipes.Add(recipe);
            WorkingUnit.Save();
        }
        public void CreateCategory(Category category)
        {
            var item = WorkingUnit.Categories.GetAll().SingleOrDefault(x => string.Equals(x.Name, category.Name, StringComparison.OrdinalIgnoreCase) && x.ParentId == category.ParentId);

            if (item != null)
            {
                Console.WriteLine($"Category {item.Name} already exists!");
                return;
            }
            if (string.IsNullOrEmpty(category.Id))
            {
                category.Id = Guid.NewGuid().ToString();
            }
            if (category.Parent == null)
            {
                category.Parent = WorkingUnit.Categories.GetAll().SingleOrDefault(x => x.Id == category.ParentId);
            }
            WorkingUnit.Categories.Add(category);
            WorkingUnit.Save();
        }