Exemplo n.º 1
0
        static RecipeFactory()
        {
            Recipe granolarBar = new Recipe(1, "Granola bar");

            granolarBar.AddIngredients(3001, 1);
            granolarBar.AddIngredients(3002, 1);
            granolarBar.AddIngredients(3003, 1);
            granolarBar.AddOutputItems(2001, 1);

            _recipes.Add(granolarBar);
        }
Exemplo n.º 2
0
        public Recipe ToDomainObject()
        {
            var recipe = new Recipe(Name, TotalMinutes, Reference);

            recipe.AddIngredients(Ingredients.Select(i => i.ToDomainObject(recipe)));
            return(recipe);
        }
Exemplo n.º 3
0
        public void AddIngredientsListNoThrow()
        {
            Recipe      recipe = new Recipe();
            Ingredients ing1   = new Ingredients(new MVC_CookBook_PSSC.Models.CommonComponents.Text("txt"), new Quantity(new MVC_CookBook_PSSC.Models.CommonComponents.Number(10), new MeasuringUnit(new MVC_CookBook_PSSC.Models.CommonComponents.ShortText("txt"))));
            Ingredients ing2   = new Ingredients(new MVC_CookBook_PSSC.Models.CommonComponents.Text("txt3"), new Quantity(new MVC_CookBook_PSSC.Models.CommonComponents.Number(10), new MeasuringUnit(new MVC_CookBook_PSSC.Models.CommonComponents.ShortText("txt"))));

            Assert.DoesNotThrow(() => recipe.AddIngredients(new List <Ingredients> {
                ing1, ing2
            }));
        }
Exemplo n.º 4
0
        private void buttonAddRecipe_Click(object sender, EventArgs e)
        {
            string recipeName = this.textBoxRecipeName.Text;
            Chef   chef       = (Chef)this.comboBoxRecipeChef.SelectedItem;

            /*
             *
             * WORKAROUND 1
             *
             * Le seteo como Chef un nuevo Chef, pero que tenga el mismo Id que el elegido, para que
             * Entity Framework pueda identificar la tupla. Esto tiene como ventaja que cuando attachee
             * al nuevo Chef y lo marque como UNCHANGED no tenga que iterar todas sus recetas y setear a ellas
             * tambien como UNCHANGED. Este nuevo Chef no tiene Recetas dado que acabo de crearlo, es un
             * Chef "ficticio" que solo me permite identificar correctamente la tupla. Esto es porque Id
             * es CLAVE PRIMARIA
             *
             */

            Recipe recipe = new Recipe()
            {
                Name = recipeName, Chef = new Chef()
                {
                    Id = chef.Id
                }
            };

            /*
             *
             * WORKAROUND 2
             *
             * Idem anterior, itero los ingredientes y me quedo solamente con sus ids para poder identificar la tupla
             * en la base, pero no me interesa tener que attachear y marcar como UNCHANGED sus entidades relacionadas
             *
             */

            /*
             *
             * ========================================================================================================
             *
             * ES IMPORTANTE ACLARAR QUE ESTE CODIGO ES INCORRECTO QUE SE HAGA EN EL PROYECTO DE INTERFAZ
             * ESTO ES UN WORKAROUND QUE DEBERIA HACERSE COMO PARTE DE LA OPERACION QUE INTERACTUE CON ENTITY FRAMEWORK
             * Y NO DENTRO DE LA VENTANA
             *
             * NO TOMEN ESTO COMO EJEMPLO DE DISENIO SOLAMENTE COMO EJEMPLO DE COMO USAR LA TECNOLOGIA
             *
             * ========================================================================================================
             *
             */

            List <Ingredient> ingredientsToAdd = new List <Ingredient>();

            foreach (var ingredient in this.ingredientsCurrentRecipe)
            {
                ingredientsToAdd.Add(new Ingredient()
                {
                    Id = ingredient.Id
                });
            }

            recipe.AddIngredients(ingredientsToAdd);

            this.recipesController.CreateRecipe(recipe);

            this.RefreshRecipes();
            this.ingredientsCurrentRecipe.Clear();
            this.RefreshIngredientsOfCurrentRecipe();
        }