Exemple #1
0
        static void Main(string[] args)
        {
            BookManager bm = new BookManager();
            int         choice;
            bool        check;

            while (true)
            {
                do
                {
                    Console.WriteLine();
                    Console.WriteLine("What would you want to do?");
                    Console.WriteLine("1. Add new book");
                    Console.WriteLine("2. Update a book");
                    Console.WriteLine("3. Delete a book");
                    Console.WriteLine("4. List all book");
                    Console.WriteLine("5. Quit");
                    Console.Write("Your choice: ");
                    check = int.TryParse(Console.ReadLine(), out choice);
                    if (!check)
                    {
                        Console.WriteLine("Choice is a number");
                    }
                    if (choice < 1 || choice > 5)
                    {
                        Console.WriteLine("Choice from 0 - 5 only");
                    }
                } while (!check || choice < 1 || choice > 5);
                switch (choice)
                {
                case 1:
                    bm.AddNewBook();
                    break;

                case 2:
                    bm.UpdateBook();
                    break;

                case 3:
                    bm.DeleteBook();
                    break;

                case 4:
                    bm.ListAllBooks();
                    break;

                case 5:
                    Console.WriteLine("Thanks for using the system!");
                    return;

                    break;
                }
            }
        }
Exemple #2
0
        public ActionResult AddBook(Book book)
        {
            Author author = null;

            author = authorManager.GetAuthorByID(book.AuthorID);
            Publisher publisher = null;

            publisher = publisherManager.GetPublisherByID(book.Publisher);

            string authorIDText = Request.Form["AuthorID"];
            int    authorID     = 0;

            int.TryParse(authorIDText, out authorID);
            book.AuthorID = authorID;
            try
            {
                UpdateModel <Book>(book);
            }
            catch (Exception) { /* book model cannot be updated */ }

            if (ModelState.IsValid)
            {
                if (bookManager.CheckISBN(book.ISBN))
                {
                    ModelState.AddModelError("", "ISBN already exists");
                    return(View());
                }
                else if (author == null)
                {
                    ModelState.AddModelError("", "Author does not exist");
                    return(View());
                }
                else if (publisher == null)
                {
                    ModelState.AddModelError("", "Publisher does not exist");
                    return(View());
                }
                else
                {
                    bookManager.AddNewBook(book);
                    return(RedirectToAction("Details", "Book", book));
                }
            }
            else
            {
                return(View());
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            BookManager lib    = new BookManager();
            char        option = '1';

            while (option != '5')
            {
                Console.WriteLine("Wellcome to my library");
                Console.WriteLine("1. Add new book");
                Console.WriteLine("2.Update a book");
                Console.WriteLine("3.Delete a book");
                Console.WriteLine("4.List all book");
                Console.WriteLine("5.Quit");
                Console.Write("Choose an option (from 1-5): ");
                option = new DataInput().CheckOption();

                switch (option)
                {
                case '1':
                    if (lib.AddNewBook(lib.AddBook()))
                    {
                        Console.WriteLine("Saved!!!");
                    }
                    else
                    {
                        Console.WriteLine("Can not add to the book!!!");
                    }
                    break;

                case '2':
                    if (lib.UpdateBookInfor())
                    {
                        Console.WriteLine("Done!!!");
                    }
                    else
                    {
                        Console.WriteLine("Can not update the book, double-check book's id " +
                                          "or amount of book in the list");
                    }
                    break;

                case '3':
                    bool result4 = lib.DeleteBook();
                    if (result4)
                    {
                        Console.WriteLine("Done!!!");
                    }
                    else
                    {
                        Console.WriteLine("Can not delete the requested book, double-check book's id " +
                                          "or amount of book in the list");
                    }
                    break;

                case '4':
                    if (lib.GetListBook().Count == 0)
                    {
                        Console.WriteLine("No book to show");
                        break;
                    }

                    lib.DisplayAllBooks();
                    break;

                case '5':
                    break;
                }
            }
        }