public ActionResult Add() // Création d'une nouvelle reservation { // Récupération data membres + livre MemberDAL memberDAL = new MemberDAL((List <Member>)Session["Members"]); List <Member> members = memberDAL.GetAll(); BookDAL bookDAL = new BookDAL((List <Book>)Session["Books"]); List <Book> books = bookDAL.GetAvailableBooks(); // Création de la réservation var model = new AddResaViewModel(); model.members = GetSelectListItemsMember(members); model.books = GetSelectListItemsBook(books); model.resa = new BooksBorrowing(); return(View(model)); }
public ActionResult Create([Bind(Include = "user, book, bookSelected, memberSelected")] AddResaViewModel model) { // Récupération data réservation + membre + livre ReservationDAL dal = new ReservationDAL((List <BooksBorrowing>)Session["BooksBorrowing"]); MemberDAL memberDAL = new MemberDAL((List <Member>)Session["Members"]); BookDAL bookDAL = new BookDAL((List <Book>)Session["Books"]); List <Member> members = memberDAL.GetAll(); List <Book> books = bookDAL.GetAll(); model.members = GetSelectListItemsMember(members); model.books = GetSelectListItemsBook(books); model.resa = new BooksBorrowing(); // Selection du livre pour la reservation Book selectedBook = bookDAL.Read(model.bookSelected); model.resa.book = selectedBook; // Mise a jour de la quantité disponible selectedBook.AvailableQuantity -= 1; bookDAL.Update(selectedBook.Id, selectedBook); Member selectedMember = memberDAL.Read(model.memberSelected); model.resa.user = selectedMember; if (ModelState.IsValid) { dal.Add(model.resa); return(RedirectToAction("Index")); } return(View("Add", model)); }