public ActionResult RemoveFromBook(int bookId, int clientId) { ClientBook clientBook = new ClientBook(); clientBook.BookId = bookId; clientBook.ClientId = clientId; clientBook.Book = db.Books.Find(bookId); clientBook.Client = db.Clients.Find(clientId); return(View(clientBook)); }
public ActionResult RemoveFromBook(ClientBook model) { var client = db.Clients.FirstOrDefault(m => m.Id == model.ClientId); var book = db.Books.FirstOrDefault(m => m.Id == model.BookId); book.Clients.Remove(client); client.Books.Remove(book); client.NumBooks = client.Books.Count; book.numOfCopiesLeft++; db.SaveChanges(); return(View("Index", db.Books.ToList())); }
public ActionResult EditLoan(EditLoanViewModel model) { LibraryDal dal = new LibraryDal(); ClientBook oldLoan = dal.GetLoan(model.clientId, model.bookId); if (ModelState.IsValid && oldLoan != null) { dal.UpdateLoan(oldLoan, model.loan); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult InsertNewClient(int id) { ClientBook model = new ClientBook(); model.BookId = id; model.Book = db.Books.Find(id); if (model.Book.numOfCopiesLeft == 0) { return(RedirectToAction("Index")); } model.Clients = db.Clients.ToList(); ViewBag.Clients = db.Clients.ToList(); return(View(model)); }