Exemplo n.º 1
0
        public static int EditBook(Book[] myBooks)
        {
            Console.WriteLine("What is the ISBN of the book you will be editing?:");
            int  editIsbn = int.Parse(Console.ReadLine());
            bool found    = false;
            int  index    = 0;

            for (int i = 0; i < Book.GetCount() && found == false; i++)
            {
                if (myBooks[i].GetIsbn() == editIsbn)
                {
                    found = true;
                    index = i;
                }
            }
            if (found != true)
            {
                Console.WriteLine("Book ISBN " + editIsbn + " not found");
            }
            else
            {
                Console.WriteLine(myBooks[index].ToString());
                EditMenu(index, myBooks);
            }

            BookFile.WriteToFile(myBooks);
            return(myBooks[index].GetIsbn());
        }
Exemplo n.º 2
0
        public static void RentBook(Book[] myBooks, Transaction[] myTransaction)
        {
            Console.WriteLine("Enter your email:");
            string email = Console.ReadLine();

            Console.WriteLine("Enter the ISBN of the Book you want to rent:");
            int  rentIsbn = int.Parse(Console.ReadLine());
            bool found    = false;

            while (found == false)
            {
                for (int i = 0; i < Book.GetCount() && found == false; i++)
                {
                    if (myBooks[i].GetInStock() == true && myBooks[i].GetIsbn() == rentIsbn)
                    {
                        myBooks[i].InStock();

                        found = true;
                    }
                }
                if (found == false)
                {
                    Console.WriteLine("Book not available for rent");

                    Console.WriteLine("Enter the ISBN of the Book you want to rent:");
                    rentIsbn = int.Parse(Console.ReadLine());
                }
            }

            if (found == true)
            {
                int      newId      = myTransaction[Transaction.GetCount() - 1].GetId() + 1;
                DateTime date       = DateTime.Today;
                string   dateToday  = date.ToString("d");
                string   returnDate = "N/A";

                myTransaction[Transaction.GetCount()] = new Transaction(newId, email, rentIsbn, dateToday, returnDate);
                Transaction.SetCount(Transaction.GetCount() + 1);

                TransactionFile.WriteToFile(myTransaction);
                BookFile.WriteToFile(myBooks);
            }
        }
Exemplo n.º 3
0
        public static void ReturnBook(Book[] myBooks, Transaction[] myTransaction)
        {
            Console.WriteLine("Enter the email used to rent the book:");
            string email = Console.ReadLine();

            Console.WriteLine("Enter the ISBN of the book you would like to return:");
            int returnId = int.Parse(Console.ReadLine());

            DateTime date      = DateTime.Today;
            string   dateToday = date.ToString("d");
            bool     found     = false;
            int      index     = 0;

            for (int i = 0; i < Book.GetCount() && found == false; i++)
            {
                for (int j = 0; j < Transaction.GetCount() && found == false; j++)
                {
                    if (myTransaction[j].GetIsbn() == returnId && myTransaction[j].GetEmail() == email && myBooks[i].GetIsbn() == returnId)
                    {
                        found = true;
                        myTransaction[j].SetReturnDate(dateToday);

                        myBooks[i].InStock();
                        index = i;
                    }
                }
            }

            if (found == true)
            {
                Console.WriteLine("You have returned " + myBooks[index].GetTitle());
                TransactionFile.WriteToFile(myTransaction);
                BookFile.WriteToFile(myBooks);
            }
            else
            {
                Console.WriteLine("Transaction not found");
            }
        }
Exemplo n.º 4
0
        public static void AddBook(Book[] myBooks)
        {
            Console.WriteLine("What is the ISBN of the new book?: ");
            int isbn = int.Parse(Console.ReadLine());

            Console.WriteLine("What is the title of the book you would like to add?");
            string title = Console.ReadLine();

            Console.WriteLine("What is the genre of the book?: ");
            string genre = Console.ReadLine();

            Console.WriteLine("Who is the author of the book?: ");
            string author = Console.ReadLine();

            Console.WriteLine("How long is the recording (in minutes)?: ");
            int  time    = int.Parse(Console.ReadLine());
            bool inStock = true;

            myBooks[Book.GetCount()] = new Book(isbn, title, genre, author, time, inStock);
            Book.SetCount(Book.GetCount() + 1);

            BookFile.WriteToFile(myBooks);
        }