public async Task <IActionResult> Create([Bind("IngredientID,item,ItemID,RecipeID,Quantity,Units")] Ingredient ingredient)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ingredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(ingredient));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("StepID,RecipeID,Description,Order")] Step step)
        {
            if (ModelState.IsValid)
            {
                _context.Add(step);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(step));
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("RecipeID,Notes,Servings")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipe);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(recipe));
        }
Example #4
0
        public async Task <IActionResult> Create([Bind("ItemID,Name,IsRecipe,ServingSize,ServingUnits,Category,UserID,CaloriesPerServing,ProteinPerServing,IsPantryItem,IsGF,RecipeID,recipe")] Item item)
        {
            if (!item.IsRecipe)
            {
                item.RecipeID = null;
            }
            else
            {
                //add recipe to database and store corresponding recipe ID in item object
                _context.Recipe.Add(item.recipe);
                await _context.SaveChangesAsync();

                item.RecipeID = item.recipe.RecipeID;

                //adding ingredients to database
                foreach (var i in item.recipe.Ingredients)
                {
                    i.RecipeID = item.recipe.RecipeID;
                    _context.Ingredient.Add(i);
                }
                await _context.SaveChangesAsync();

                //adding instructions to database
                foreach (var i in item.recipe.Instructions)
                {
                    i.RecipeID = item.recipe.RecipeID;
                    _context.Step.Add(i);
                }
                await _context.SaveChangesAsync();
            }

            if (ModelState.IsValid)
            {
                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }