예제 #1
0
        static void Main(string[] args)
        {
            string      fileName = SetFileName();
            CardCatalog cc       = new CardCatalog(fileName);
            string      result   = "";

            while (result != "3")
            {
                Console.Clear();

                Console.WriteLine("Greetings, \n\n");
                Console.WriteLine("Please select an option:");
                Console.WriteLine("1) List All Books");
                Console.WriteLine("2) Add a Book");
                Console.WriteLine("3) Save and Exit");

                result = Console.ReadLine();
                if (result == "1")
                {
                    cc.ListBooks();
                }
                if (result == "2")
                {
                    cc.AddBook("");
                }
                if (result == "3")
                {
                    cc.Save();
                }
            }

            Console.ReadLine();
        }
예제 #2
0
        public static bool MainMenu(CardCatalog cc)
        {
            Console.WriteLine("1) List all books.");
            Console.WriteLine("2) Add a book.");
            Console.WriteLine("3) Save and Exit.");
            string result = Console.ReadLine();

            if (result == "1")
            {
                cc.ListAllBooks();
                return(true);
            }
            else if (result == "2")
            {
                cc.AddABook();
                return(true);
            }
            else if (result == "3")
            {
                cc.Save();
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter the Name of a File: ");
            string fileToUse = Console.ReadLine();

            CardCatalog currentCardCatalog = new CardCatalog(fileToUse);

            Console.Clear();

            bool stillGoing = true;

            while (stillGoing == true)
            {
                Console.WriteLine("CHOOSE AN OPTION 1 - 3 for {0}\n\n1. List All books\n2. Add A Book\n3. Save and Exit", fileToUse);
                int userInput = MakeItTheRightInt(Console.ReadKey(true).KeyChar.ToString());
                switch (userInput)
                {
                case 1:
                    currentCardCatalog.ListBooks();
                    break;

                case 2:
                    currentCardCatalog.AddBook();
                    break;

                case 3:
                    currentCardCatalog.Save();
                    stillGoing = false;
                    break;

                default:
                    break;
                }
            }
        }
예제 #4
0
        static private void PromptMenuForUser(CardCatalog cardCatalog)
        {
            int userChoice;

            while (true)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("1. List All Books\n" +
                                  "2. Add A Book\n" +
                                  "3. Save And Exit");

                Console.Write("Input your choice: ");

                if (int.TryParse(Console.ReadLine(), out userChoice))
                {
                    if (userChoice == 1)
                    {
                        //List all the books
                        //replay the menu
                        cardCatalog.ListBooks();
                    }
                    else if (userChoice == 2)
                    {
                        //Add a book to the userfile
                        //replay the menu
                        cardCatalog.AddBook();
                    }
                    else if (userChoice == 3)
                    {
                        //Save all the books added to the userfile
                        //close the menu
                        cardCatalog.Save();
                        break;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Please choose from the above!\n" +
                                          "Thank you!");
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Reads the user's selection and calls the appropriate CardCatalog action
        /// </summary>
        /// <param name="c">current CardCatalog object</param>
        /// <param name="userSelection">User's menu choice (could be 1, 2, or 3.</param>
        private static void RouteUserRequest(CardCatalog c, int userSelection)
        {
            while (userSelection != 3)
            {
                if (userSelection == 1)
                {
                    c.ListBooks();
                }
                else if (userSelection == 2)
                {
                    c.AddBook(c.CreateBook());
                }

                userSelection = GetValidUserInput();
            }
            if (userSelection == 3)
            {
                c.Save();
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the name of the file: ");
            string      fileName   = Console.ReadLine();
            CardCatalog newCatalog = new CardCatalog(fileName);

            Console.Clear();
            int option = 0;

            do
            {
                Console.Clear();
                Console.WriteLine("1. List All books");
                Console.WriteLine("2. Add a book ");
                Console.WriteLine("3. Save and Exit");
                string inputChoice = Console.ReadLine();
                int.TryParse(inputChoice, out option);
                switch (option)
                {
                case 1:

                    Console.WriteLine("List of books in Card Catalog: ");


                    if (File.Exists(fileName))
                    {
                        XDocument doc = XDocument.Load(fileName);

                        var books = doc.Descendants("Title");

                        foreach (var book in books)
                        {
                            Console.WriteLine(book.Value);
                        }
                    }
                    else
                    {
                        Console.WriteLine("File name does not exist. Select option number 2 to add books or 3 to exit. ");
                    }

                    Console.ReadLine();



                    break;

                case 2:
                    Console.WriteLine("Enter the book author name");
                    string author = Console.ReadLine();
                    Console.WriteLine("Enter the book title name");
                    string title = Console.ReadLine();
                    Console.WriteLine("Enter the book year");
                    string year = Console.ReadLine();
                    newCatalog.books.Add(new Book {
                        Author = author, Title = title, Year = year
                    });
                    break;

                case 3:
                    newCatalog.Save(fileName);
                    break;
                }
            } while (option != 3);
        }