Exemplo n.º 1
0
        public ActionResult EditBook(int id)
        {
            LibraryManagementSystemContext context    = new LibraryManagementSystemContext();
            BooksRepository      booksRepository      = new BooksRepository(context);
            PublishersRepository publishersRepository = new PublishersRepository(context);
            BooksEditBookVM      model = new BooksEditBookVM();

            Book book = booksRepository.GetByID(id);

            if (id > 0)
            {
                if (book == null)
                {
                    return(RedirectToAction("Index", "Books"));
                }

                model.ID            = book.ID;
                model.Title         = book.Title;
                model.PublisherID   = book.Publisher.ID;
                model.StockCount    = book.StockCount;
                model.DeliveryPrice = book.DeliveryPrice;
                model.DateReceived  = book.DateReceived;
                model.DatePublished = book.DatePublished;
            }
            else
            {
                book = new Book();
            }

            model.Publishers = model.Publishers ?? new List <SelectListItem>();
            model.Publishers = SelectListHandler.Create <Publisher>(
                publishersRepository.GetAll(), p => p.Name, p => p.ID.ToString(), model.PublisherID.ToString());

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult AddBookAuthor(int id)
        {
            LibraryManagementSystemContext context = new LibraryManagementSystemContext();
            BooksRepository      booksRepository   = new BooksRepository(context);
            AuthorsRepository    authorsRepository = new AuthorsRepository(context);
            BooksAddBookAuthorVM model             = new BooksAddBookAuthorVM();

            Book book = booksRepository.GetByID(id);

            model.ID      = book.ID;
            model.Title   = book.Title;
            model.Authors = model.Authors ?? new List <SelectListItem>();
            model.Authors = SelectListHandler.Create <Author>(
                authorsRepository.GetAll(), a => (a.FirstName + " " + a.LastName), a => a.ID.ToString(), model.AuthorID.ToString());

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult EditBook(BooksEditBookVM model)
        {
            LibraryManagementSystemContext context    = new LibraryManagementSystemContext();
            BooksRepository      booksRepository      = new BooksRepository(context);
            PublishersRepository publishersRepository = new PublishersRepository(context);

            Book book = null;

            if (!ModelState.IsValid)
            {
                model.Publishers = model.Publishers ?? new List <SelectListItem>();
                model.Publishers = SelectListHandler.Create <Publisher>(
                    publishersRepository.GetAll(), p => p.Name, p => p.ID.ToString(), model.PublisherID.ToString());
                return(View(model));
            }
            else
            {
                if (model.ID > 0)
                {
                    book = booksRepository.GetByID(model.ID);
                }
                else
                {
                    book = new Book();
                }

                book.ID            = model.ID;
                book.Title         = model.Title;
                book.PublisherID   = model.PublisherID;
                book.StockCount    = model.StockCount;
                book.DeliveryPrice = model.DeliveryPrice;
                book.DateReceived  = model.DateReceived;
                book.DatePublished = model.DatePublished;

                booksRepository.Save(book);
            }

            return(RedirectToAction("Index", "Books"));
        }