示例#1
0
        public ActionResult AddIngredientspost(Ingredient ing)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //add ingredient

                    db.Ingredients.Add(ing);
                    db.SaveChanges();
                    //add ingredient to list
                    myIngredients.Add(ing);
                    //when finshed is called iterate over list and add to database

                    //return to add ingredients view
                    //recipeid persists first time to here
                    int recipeid = ing.RecipeID;
                    return RedirectToAction("AddIngredients",ing);
                }
            }
            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists call Niall.");
            }

            return View(ing);
        }
示例#2
0
        public ActionResult AddIngredients(Ingredient ing)
        {
            //create new ingredient
             Ingredient newIng = new Ingredient();
            //assign id from previous ingredient
            newIng.RecipeID = ing.RecipeID;

            //display list of ingredients
            //TODO
            //Add Finish button to redirect to add instructions controller action
            ViewBag.theMessage = "Add your ingredients.";
            //recipe id persists to here
            return View(newIng);
        }
示例#3
0
        public ActionResult AddMoreIngredients(Ingredient ing)
        {
            //create new ingredient
            Ingredient newIng = new Ingredient();
            //assign id from previous ingredient
            newIng.RecipeID = ing.RecipeID;
            try
            {
                if (ModelState.IsValid)
                {
                    //add ingredient

                    //db.Ingredients.Add(newIng);
                    //db.SaveChanges();
                    //add ingredient to list
                    myIngredients.Add(newIng);
                    int recipeid = newIng.RecipeID;

                    //return to add ingredients view
                    //recipeid persists first time to here
                    return RedirectToAction("AddMoreIngredients", recipeid);
                }
            }
            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see call Niall.");
            }

            //display list of ingredients
            //TODO
            //Add Finish button to redirect to add instructions controller action
            ViewBag.theMessage = "Add your ingredients.";

            return View(newIng);
        }
示例#4
0
        public ActionResult AddMoreIngredients(int recipeid)
        {
            //create new ingredient
            Ingredient newIng = new Ingredient();
            //assign id from previous ingredient
            newIng.RecipeID = recipeid;
            //add ingredient to database

            //display list of ingredients
            //TODO
            //Add Finish button to redirect to add instructions controller action
            ViewBag.theMessage = "Add your ingredients.";

            return View(newIng);
        }