public ActionResult CreateCookBook(CreateCookBookModel model)
        {
            CookBook cookBook = new CookBook();

            cookBook.Title    = model.Title;
            cookBook.SubTitle = model.SubTitle;
            cookBook.Content  = model.Content;
            cookBook.Image    = model.Image;

            db.CookBooks.Add(cookBook);
            db.SaveChanges();

            foreach (var step in model.Steps)
            {
                CookBookStep cookBookStep = new CookBookStep();
                cookBookStep.OrderID    = model.Steps.IndexOf(step);
                cookBookStep.ImageUrl   = step.ImageUrl;
                cookBookStep.Content    = step.Content;
                cookBookStep.CookBookID = cookBook.ID;
                cookBookStep.CookBook   = cookBook;

                db.CookBookSteps.Add(cookBookStep);
            }

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CookBookStep cookBookStep = db.CookBookSteps.Find(id);

            db.CookBookSteps.Remove(cookBookStep);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "StepID,OrderID,ImageUrl,Content,CookBookID")] CookBookStep cookBookStep)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cookBookStep).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CookBookID = new SelectList(db.CookBooks, "ID", "Title", cookBookStep.CookBookID);
     return(View(cookBookStep));
 }
        // GET: MngCookBookStep/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CookBookStep cookBookStep = db.CookBookSteps.Find(id);

            if (cookBookStep == null)
            {
                return(HttpNotFound());
            }
            return(View(cookBookStep));
        }
        // GET: MngCookBookStep/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CookBookStep cookBookStep = db.CookBookSteps.Find(id);

            if (cookBookStep == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CookBookID = new SelectList(db.CookBooks, "ID", "Title", cookBookStep.CookBookID);
            return(View(cookBookStep));
        }