Ejemplo n.º 1
0
 public StockTest()
 {
     ingrediantUn   = new Ingrediant();
     IngrediantDeux = new Ingrediant();
     array          = new Ingrediant[2] {
         ingrediantUn, IngrediantDeux
     };
 }
Ejemplo n.º 2
0
        public async Task <List <Recipe> > LoadRecipes()
        {
            List <Recipe> recipes = new List <Recipe>();

            try
            {
                using (SqlConnection connection = new SqlConnection(_settings.ConnectionString))
                {
                    await connection.OpenAsync().ConfigureAwait(false);

                    using (SqlCommand cmd = new SqlCommand(LOAD_RECIPES, connection))
                    {
                        using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
                        {
                            while (await reader.ReadAsync().ConfigureAwait(false))
                            {
                                Recipe recipe = new Recipe();
                                recipe.ID          = Convert.ToInt32(reader["ID"]);
                                recipe.Name        = Convert.ToString(reader["RecipeName"]);
                                recipe.Description = Convert.ToString(reader["Description"]);
                                recipe.ImgPath     = Convert.ToString(reader["ImgPath"]);
                                recipe.DateCreated = Convert.ToDateTime(reader["DateCreated"]);
                                recipe.Ingrediants = new List <Ingrediant>();
                                recipes.Add(recipe);
                            }
                        }
                    }

                    using (SqlCommand cmd = new SqlCommand(LOAD_INGREDIANTS, connection))
                    {
                        using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false))
                        {
                            while (await reader.ReadAsync().ConfigureAwait(false))
                            {
                                Ingrediant ingrediant = new Ingrediant();
                                ingrediant.ID       = Convert.ToInt32(reader["ID"]);
                                ingrediant.RecipeID = Convert.ToInt32(reader["RecipeID"]);
                                ingrediant.Name     = Convert.ToString(reader["Name"]);
                                ingrediant.Count    = Convert.ToInt32(reader["Count"]);

                                Recipe recipe = recipes.Where(x => x.ID == ingrediant.RecipeID).First();
                                recipe.Ingrediants.Add(ingrediant);
                            }
                        }
                    }
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(recipes);
        }
Ejemplo n.º 3
0
        public async Task <Recipe> LoadRecipe(int recipeID)
        {
            Recipe recipe = new Recipe();

            using (SqlConnection connection = new SqlConnection(_settings.ConnectionString))
            {
                await connection.OpenAsync().ConfigureAwait(false);

                using (SqlCommand cmd = new SqlCommand(LOAD_RECIPE, connection))
                {
                    cmd.Parameters.Add("@ID", SqlDbType.Int).Value = recipeID;

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            recipe.ID          = Convert.ToInt32(reader["ID"]);
                            recipe.Name        = Convert.ToString(reader["RecipeName"]);
                            recipe.Description = Convert.ToString(reader["Description"]);
                            recipe.ImgPath     = Convert.ToString(reader["ImgPath"]);
                            recipe.Ingrediants = new List <Ingrediant>();
                        }
                    }
                }

                using (SqlCommand cmd = new SqlCommand(LOAD_INGREDIANT, connection))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        cmd.Parameters.Add("@RecipeID", SqlDbType.Int).Value = recipeID;

                        while (reader.Read())
                        {
                            Ingrediant ingrediant = new Ingrediant();
                            ingrediant.ID       = Convert.ToInt32(reader["ID"]);
                            ingrediant.RecipeID = Convert.ToInt32(reader["RecipeID"]);
                            ingrediant.Name     = Convert.ToString(reader["Name"]);
                            ingrediant.Count    = Convert.ToInt32(reader["Count"]);
                            recipe.Ingrediants.Add(ingrediant);
                        }
                    }
                }
                connection.Close();
            }
            return(recipe);
        }
Ejemplo n.º 4
0
            public RecipeTestData()
            {
                #region Init Recipe

                // ------------------- Generel ----------------------
                Recipe = new Recipe()
                {
                    Name             = "My Recipe",
                    Id               = 1,
                    Calories         = 1,
                    CookedCounter    = 2,
                    Creator          = "Tester",
                    LastTimeCooked   = new DateTime(),
                    NumberOfServings = 3
                };

                // ------------------- Images ----------------------
                var image = new RecipeImage()
                {
                    Recipe   = this.Recipe,
                    Id       = 1,
                    RecipeId = Recipe.Id,
                    Url      = "http://imageUrl.de",
                    Filename = "MyImage.jpg"
                };
                Recipe.Images.Add(image);

                // ------------------- Steps ----------------------

                var steps = new List <RecipeStep>()
                {
                    new RecipeStep()
                    {
                        Recipe = Recipe, Id = 1, RecipeId = Recipe.Id, Order = 0, Description = "Step 1"
                    },
                    new RecipeStep()
                    {
                        Recipe = Recipe, Id = 2, RecipeId = Recipe.Id, Order = 1, Description = "Step 2"
                    }
                };
                Recipe.Steps.AddRange(steps);

                // ------------------- Tags ----------------------

                var tags = new List <RecipeTag>()
                {
                    new RecipeTag()
                    {
                        Id = 1, Name = "Tag 1"
                    },
                    new RecipeTag()
                    {
                        Id = 2, Name = "Tag 2"
                    },
                };

                var recipeTags = new List <RecipeRecipeTag>()
                {
                    new RecipeRecipeTag()
                    {
                        Recipe = Recipe, RecipeId = Recipe.Id, RecipeTag = tags.First(), RecipeTagId = tags.First().Id
                    },
                    new RecipeRecipeTag()
                    {
                        Recipe = Recipe, RecipeId = Recipe.Id, RecipeTag = tags.Last(), RecipeTagId = tags.Last().Id
                    },
                };

                tags.First().Recipes.Add(recipeTags.First());
                tags.Last().Recipes.Add(recipeTags.Last());
                Recipe.Tags.AddRange(recipeTags);

                // ------------------- Source ----------------------

                var source = new RecipeUrlSource()
                {
                    Id   = 1,
                    Name = "WebSource",
                    Url  = "http://www.websource.de"
                };
                var recipeSource = new RecipeSourceRecipe()
                {
                    Page     = 0,
                    Recipe   = Recipe,
                    RecipeId = Recipe.Id,
                    Source   = source,
                    SourceId = source.Id
                };
                source.RecipeSourceRecipes.Add(recipeSource);
                Recipe.Source   = recipeSource;
                Recipe.SourceId = source.Id;

                // ------------------- Ingrediant ----------------------

                var ingrediant = new Ingrediant()
                {
                    Id   = 1,
                    Name = "Ingrediant 1"
                };

                var recipeIngrediant = new RecipeIngrediant()
                {
                    Recipe       = Recipe,
                    RecipeId     = Recipe.Id,
                    Ingrediant   = ingrediant,
                    IngrediantId = ingrediant.Id,
                    Amount       = 1,
                    CookingUnit  = CookingUnit.Gramm
                };
                ingrediant.Recipes.Add(recipeIngrediant);
                Recipe.Ingrediants.Add(recipeIngrediant);

                #endregion
                UpdateModel = new RecipeUpdateViewModel()
                {
                    Id               = 1,
                    Name             = "Old Recipe",
                    Url              = "http://www.webservice.de/recipes/1",
                    Calories         = Recipe.Calories.GetValueOrDefault(),
                    NumberOfServings = Recipe.NumberOfServings
                };
                CreationModel = new RecipeCreationViewModel()
                {
                    Name             = UpdateModel.Name,
                    Calories         = UpdateModel.Calories,
                    NumberOfServings = UpdateModel.NumberOfServings,
                    Creator          = Recipe.Creator
                };
            }
Ejemplo n.º 5
0
        private void InitLocalTestData()
        {
            //-------------------- Recipes ---------------------------------------

            var recipe1 = new Recipe()
            {
                Id               = 0,
                Name             = "Recipe 1",
                Calories         = 1,
                CookedCounter    = 0,
                Creator          = "Tester",
                LastTimeCooked   = new DateTime(),
                NumberOfServings = 1
            };

            var recipe2 = new Recipe()
            {
                Id               = 0,
                Name             = "Recipe 2",
                Calories         = 1,
                CookedCounter    = 0,
                Creator          = "Tester",
                LastTimeCooked   = new DateTime(),
                NumberOfServings = 1
            };

            this.Recipes.Add(recipe1);
            this.Recipes.Add(recipe2);

            //-------------------- Sources ---------------------------------------

            var cookbookSource = new RecipeCookbookSource()
            {
                Id   = 0,
                ISBN = "ISBN 978-3-86680-192-9",
                Name = "Cookbook 1",
                PublishingCompany = "ABC Corp"
            };

            var webSource = new RecipeUrlSource()
            {
                Id   = 0,
                Name = "Chefkoch.de",
                Url  = "http://www.chefkoch.de/recipe/1"
            };

            this.Sources.Add(cookbookSource);
            this.Sources.Add(webSource);

            //-------------------- Steps ---------------------------------------

            var recipe1Step1 = new RecipeStep()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Order = 0, Description = "Desc 1"
            };
            var recipe1Step2 = new RecipeStep()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Order = 1, Description = "Desc 2"
            };
            var recipe2Step1 = new RecipeStep()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Order = 0, Description = "Desc 1"
            };
            var recipe2Step2 = new RecipeStep()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Order = 1, Description = "Desc 2"
            };
            var recipe2Step3 = new RecipeStep()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Order = 2, Description = "Desc 3"
            };

            this.Steps.Add(recipe1Step1);
            this.Steps.Add(recipe1Step2);
            this.Steps.Add(recipe2Step1);
            this.Steps.Add(recipe2Step2);
            this.Steps.Add(recipe2Step3);

            recipe1.Steps.Add(recipe1Step1);
            recipe1.Steps.Add(recipe1Step2);

            recipe2.Steps.Add(recipe2Step1);
            recipe2.Steps.Add(recipe2Step2);
            recipe2.Steps.Add(recipe2Step3);

            var ingrediant1 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 1"
            };
            var ingrediant2 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 2"
            };
            var ingrediant3 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 3"
            };
            var ingrediant4 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 4"
            };
            var ingrediant5 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 5"
            };

            this.Ingrediants.Add(ingrediant1);
            this.Ingrediants.Add(ingrediant2);
            this.Ingrediants.Add(ingrediant3);
            this.Ingrediants.Add(ingrediant4);
            this.Ingrediants.Add(ingrediant5);

            //-------------------- Images ---------------------------------------

            var image1 = new RecipeImage()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Filename = "File1.jpg", Url = "http://www.service.de/images/1"
            };
            var image2 = new RecipeImage()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Filename = "File2.jpg", Url = "http://www.service.de/images/2"
            };
            var image3 = new RecipeImage()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Filename = "File3.jpg", Url = "http://www.service.de/images/3"
            };

            this.Images.Add(image1);
            this.Images.Add(image2);
            this.Images.Add(image3);

            recipe1.Images.Add(image1);
            recipe1.Images.Add(image2);
            recipe2.Images.Add(image3);

            //-------------------- Tags ---------------------------------------

            var tag1 = new RecipeTag()
            {
                Id = 0, Name = "Tag 1"
            };
            var tag2 = new RecipeTag()
            {
                Id = 0, Name = "Tag 2"
            };
            var tag3 = new RecipeTag()
            {
                Id = 0, Name = "Tag 3"
            };
            var tag4 = new RecipeTag()
            {
                Id = 0, Name = "Tag 4"
            };

            this.Tags.Add(tag1);
            this.Tags.Add(tag2);
            this.Tags.Add(tag3);
            this.Tags.Add(tag4);
        }