/// <summary>
        /// Checks for items with a modified quantity to update in the selected recipe
        /// </summary>
        /// <returns>List of ingredients to update quantity for</returns>
        public List <RecipeContentModel> GetIngredientsWithDifferentQty(List <RecipeAndContentModel> savedRecipe, List <RecipeAndContentModel> selectedRecipeContent)
        {
            List <RecipeAndContentModel> CommonIngredients = new List <RecipeAndContentModel>();

            foreach (var item in savedRecipe)
            {
                RecipeAndContentModel selectedIngredient = selectedRecipeContent.Where(c => c.ProductId == item.ProductId).FirstOrDefault();
                RecipeAndContentModel savedIngredient    = savedRecipe.Where(c => c.ProductId == item.ProductId).FirstOrDefault();

                if (selectedIngredient != null && selectedIngredient.ProductQuantity != savedIngredient.ProductQuantity)
                {
                    CommonIngredients.Add(selectedIngredient);
                }
            }

            List <RecipeContentModel> Output = new List <RecipeContentModel>();

            foreach (var item in CommonIngredients)
            {
                Output.Add(new RecipeContentModel {
                    ProductId = item.ProductId, RecipeId = savedRecipe[0].RecipeId, ProductQuantity = item.ProductQuantity
                });
            }

            return(Output);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the groupbox with details about the ingredient availability
        /// </summary>
        private void IngredientsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            RecipeAndContentModel recipeContentProduct = (RecipeAndContentModel)IngredientsListBox.SelectedItem;

            if (recipeContentProduct != null)
            {
                InitializeIngredientStockDetails_GroupBox(recipeContentProduct.ProductId);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Removes an ingredient from a recipe(new or existing one)
        /// </summary>
        private void RemoveRecipeItemButton_Click(object sender, EventArgs e)
        {
            RecipeAndContentModel ingredient = (RecipeAndContentModel)SelectedRecipeContentListbox.SelectedItem;

            if (ingredient.ProductQuantity > 1)
            {
                SelectedRecipeContent[SelectedRecipeContent.IndexOf(ingredient)].ProductQuantity--;
            }
            else
            {
                SelectedRecipeContent.Remove(ingredient);
            }

            InitializeRecipeContentList();
        }
Esempio n. 4
0
        /// <summary>
        /// Adds an ingredient to a recipe(new or existing one)
        /// </summary>
        private void AddRecipeItemButton_Click(object sender, EventArgs e)
        {
            ProductModel p = (ProductModel)ProductsListBox.SelectedItem;

            if (SelectedRecipeContent.Where(c => c.ProductId == p.Id).Count() > 0)
            {
                RecipeAndContentModel racm = SelectedRecipeContent.Where(c => c.ProductId == p.Id).First();
                SelectedRecipeContent[SelectedRecipeContent.IndexOf(racm)].ProductQuantity++;
            }
            else
            {
                SelectedRecipeContent.Add(new RecipeAndContentModel {
                    ProductId       = p.Id,
                    ProductName     = p.Name,
                    ProductQuantity = 1
                });
            }
            InitializeRecipeContentList(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Displays the ingredient quantity in "()", left of the ingredient name, in the selected recipe content listbox
        /// </summary>
        private void SelectedRecipeContentListbox_Format(object sender, ListControlConvertEventArgs e)
        {
            RecipeAndContentModel ingredient = ((RecipeAndContentModel)e.ListItem);

            e.Value = $"({ingredient.ProductQuantity}) {ingredient.ProductName}";
        }