[ValidateAntiForgeryToken] // Pour l'édition d'un livre public ActionResult Edition([Bind(Include = "book, authorSelected")] EditBookModelView model) { // Récupération des datas BookDAL dal = new BookDAL((List <Book>)Session["Books"]); AuthorDAL authorDAL = new AuthorDAL((List <Author>)Session["Authors"]); List <Author> authors = authorDAL.GetAll(); model.authors = GetSelectListItems(authors); Author selectedAuthor = authorDAL.Read(model.authorSelected); model.book.Author = selectedAuthor; // Attribuer l'auteur if (ModelState.IsValid) { dal.Update(model.book.Id, model.book); // Mise à jour des datas du livres return(RedirectToAction("Index")); // Si déroulement OK, retour à la liste de livres } return(View("Edit", model)); // Si erreur, on reste sur le formulaire d'edition }
public ActionResult Edit(int id) // Pour l'édition d'un livre { // Récupération des infos sur l'auteur AuthorDAL authorDAL = new AuthorDAL((List <Author>)Session["Authors"]); List <Author> authors = authorDAL.GetAll(); // Récupération des infos sur le livre BookDAL bookDAL = new BookDAL((List <Book>)Session["Books"]); Book book = bookDAL.Read(id); bookDAL.Update(id, book); // MAJ du livre //Données mises à jour renvoyées dans la vue var model = new EditBookModelView(); model.book = book; model.authors = GetSelectListItems(authors); // Données retournée à la vue return(View(model)); }