Пример #1
0
        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));
        }
Пример #2
0
        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()));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }