コード例 #1
0
        public IEnumerable <Recipe> FindAllRecipes(RecipeDataGateway context)
        {
            ObservableCollection <Recipe> newRecipe = new ObservableCollection <Recipe>();

            foreach (var item in context.Recipes.Include(n => n.Components))
            {
                newRecipe.Add(item.ToRecipe());
            }
            return(newRecipe);
        }
コード例 #2
0
        public bool tryDeleteRecipe(Recipe recipe, RecipeDataGateway context)
        {
            var lastSize = context.Recipes.Count();

            try
            {
                //context.Recipes.Remove(recipe);
                context.SaveChanges();
            }
            catch
            {
            }
            return(lastSize > context.Recipes.Count());
        }
コード例 #3
0
        public void AddRecipe(Recipe recipe, RecipeDataGateway context)
        {
            ObservableCollection <ComponentEntity> newComponents = new ObservableCollection <ComponentEntity>();

            foreach (var item in recipe.Components)
            {
                newComponents.Add(
                    new ComponentEntity(item.Id,
                                        new IngredientEntity(item.Ingredient.Id, item.Ingredient.Name),
                                        item.Quantity,
                                        new UnitEntity(item.Unit.Id, item.Unit.SingularName, item.Unit.PluralName)
                                        ));
            }
            context.Recipes.Add(new RecipeEntity(recipe.Id, recipe.Name, newComponents));
            context.SaveChanges();
        }
コード例 #4
0
        public Unit FindUnitById(int unitId, RecipeDataGateway context)
        {
            IEnumerable <Unit> names = from n in context.Units where (n.Id == unitId) select n.ToUnit();

            return(names.ElementAt(0));
        }
コード例 #5
0
        public Recipe FindRecipeByName(string recipeName, RecipeDataGateway context)
        {
            IEnumerable <Recipe> names = from n in context.Recipes.Include(n => n.Components) where (n.Name == recipeName) select n.ToRecipe();

            return(names.ElementAt(0));
        }
コード例 #6
0
        public Recipe FindRecipeById(int recipeId, RecipeDataGateway context)
        {
            IEnumerable <Recipe> names = from n in context.Recipes.Include(n => n.Components) where (n.Id == recipeId) select n.ToRecipe();

            return(names.ElementAt(0));
        }
コード例 #7
0
        public Ingredient FindIngredientById(int ingredientId, RecipeDataGateway context)
        {
            IEnumerable <Ingredient> names = from n in context.Ingredients where (n.Id == ingredientId) select n.ToIngredient();

            return(names.ElementAt(0));
        }
コード例 #8
0
 public IEnumerable <Component> FindComponentsByRecipeId(int recipeId, RecipeDataGateway context)
 {
     throw new NotImplementedException();/*
                                          * IEnumerable<Component> names = from n in context.Recipes where (n.Id == recipeId) select n.Components;
                                          * return names;*/
 }
コード例 #9
0
 public Component FindComponentById(int componentId, RecipeDataGateway context)
 {
     throw new NotImplementedException();
 }