Beispiel #1
0
        public ActionResult Create(Book book1)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.books.Add(book1);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                else
                {
                    ViewBag.GenreId = new SelectList(db.genres, "GenreId", "Genre",book1.BookId);
                    ViewBag.WriterId = new SelectList(db.writers, "WriterId", "Writer",book1.WriterId);
                    return View();
                }

            }
            catch
            {
                return View();
            }
        }
Beispiel #2
0
        public ActionResult Edit(int id, Book book3)
        {
            try
            {

                if (ModelState.IsValid)
                {
                    db.Entry(book3).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                else
                {
                    return View();
                }
            }
            catch
            {
                return View();
            }
        }