Ejemplo n.º 1
0
        public ActionResult Create(Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name", book.AuthorId);
            ViewBag.CatagoryId = new SelectList(db.Catagories, "Id", "Name", book.CatagoryId);
            ViewBag.PublisherId = new SelectList(db.Publishers, "Id", "Name", book.PublisherId);
            return View(book);
        }
Ejemplo n.º 2
0
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name", book.AuthorId);
     ViewBag.CatagoryId = new SelectList(db.Catagories, "Id", "Name", book.CatagoryId);
     ViewBag.PublisherId = new SelectList(db.Publishers, "Id", "Name", book.PublisherId);
     return View(book);
 }