コード例 #1
0
 public ActionResult Edit(Author author)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
コード例 #2
0
        public ActionResult Edit(Book book, int[] idAuthors)
        {
            Book update_book = db.Books.Find(book.BookId);

            update_book.Name    = book.Name;
            update_book.Pages   = book.Pages;
            update_book.Edition = book.Edition;
            if (ModelState.IsValid)
            {
                update_book.Authors.Clear();
                if (idAuthors != null)
                {
                    foreach (var auth in db.Authors.Where(a => idAuthors.Contains(a.AuthorId)))
                    {
                        update_book.Authors.Add(auth);
                    }
                }
                db.Entry(update_book).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(book));
        }