Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            LibraryDataBase db   = new LibraryDataBase();
            Book            book = db.Books.Find(id);

            book.Author.QuantityBooks--;
            book.Publisher.QuantityBooks--;
            db.Books.Remove(book);
            db.SaveChanges();

            FreeUnusedMemory(db);
            return(RedirectToAction("ViewAll"));
        }
Exemplo n.º 2
0
        public ActionResult Edit(SimpleBook sBook)
        {
            LibraryDataBase db   = new LibraryDataBase();
            Book            book = db.Books.Find(sBook.BookRef);

            ModifyAuthor(book, sBook, db);
            ModifyGenre(book, sBook, db);
            ModifyPublisher(book, sBook, db);
            ModifyTitle(book, sBook);

            db.Entry(book).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            FreeUnusedMemory(db);
            return(RedirectToAction("ViewAll"));
        }
Exemplo n.º 3
0
        private void FreeUnusedMemory(LibraryDataBase db)
        {
            foreach (Author a in db.Authors)
            {
                if (a.QuantityBooks == 0)
                {
                    db.Authors.Remove(a);
                }
            }

            foreach (Publisher p in db.Publishers)
            {
                if (p.QuantityBooks == 0)
                {
                    db.Publishers.Remove(p);
                }
            }
            db.SaveChanges();
        }
Exemplo n.º 4
0
        public ActionResult AddNew(SimpleBook sBook)
        {
            LibraryDataBase db   = new LibraryDataBase();
            Book            book = new Book();

            book.Author = new Author {
                AuthorName = ""
            };
            book.Publisher = new Publisher {
                PublisherName = ""
            };

            ModifyAuthor(book, sBook, db);
            ModifyGenre(book, sBook, db);
            ModifyPublisher(book, sBook, db);
            ModifyTitle(book, sBook);

            db.Books.Add(book);
            db.SaveChanges();

            FreeUnusedMemory(db);
            return(RedirectToAction("ViewAll"));
        }