Пример #1
0
        //returns a book to inventory
        public static UserFees Return(List <Book> books, UserFees user)
        {
            bool isfound = false;

            Console.WriteLine("Enter the title of the book you'd like to return.");
            string title = Console.ReadLine().ToLower();

            foreach (Book book in books)                                               //check for title match(only show titles checked out, check if returned ontime
            {
                if (title.Contains(book.Title.ToLower()) && book.StatusCheck == false) //matches title and is checked out
                {
                    isfound = true;
                    Console.WriteLine("Is " + book.StatusCheck + " by " + book.Author + " the book you are returning? [ Y ]  [ N ]");
                    string returning = Console.ReadLine().ToLower();
                    if (returning == "y" || returning == "yes")
                    {
                        if (book.Due.Ticks < DateTime.Now.Ticks) //not returned on time = late fees & hold on checkouts(name)
                        {
                            var    daysLate = (Book.DueDate().Subtract(book.Due).Days) - 1;
                            double fee      = (daysLate) * .25;
                            Console.WriteLine("\nThank you for returning this but it is " + (daysLate) + " days passed the due date.\n" +
                                              "We charge a quarter a day, so that totals to " + fee + " in late fees\n" +
                                              "If you want to checkout another book you must first take care of the fee in your account.\n");
                            user.LateFee = fee;
                            user.Good    = false;
                        }
                        book.StatusCheck = true;
                        book.Due         = Book.DueDate();
                        Console.WriteLine(book.ToString());
                    }
                }
            }
            if (!isfound)
            {
                Console.WriteLine("Sorry, we dont have a title checked out in our library by that name.");
                isfound = false;
            }
            return(user);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, please enter the name that will be used for your account.");
            string   name = Console.ReadLine();
            UserFees user = new UserFees(name, 0, true, userBooks);

            //public book list to add/edit/delete items
            ManageBooks.BookStream(books);

            bool menu = true;

            while (menu)
            {
                Console.WriteLine("\n Welcome to your inventory menu, please enter the # matching the option you want.\n\n" +
                                  "[ 1 ]List Books  [ 2 ]Add Book  [ 3 ]Checkout  [ 4 ]Return  [ 5 ]Search [ 6 ]Account");
                int menuNum = TryParse();//validate input is int
                switch (menuNum)
                {
                case 1:    //List all book
                    ManageBooks.Update(books);
                    ManageBooks.ListBooks();
                    break;

                case 2:    //Adds a new book
                    string title   = Get("Enter the Title:");
                    string author  = Get("Enther the Author:");
                    string about   = Get("What the book is about?");
                    Book   newBook = new Book(title, author, about, true, DateTime.Today);
                    books.Add(ManageBooks.Add(newBook));
                    ManageBooks.Update(books);
                    Console.WriteLine("Thank you for adding " + title + " by " + author + " to our library");
                    break;

                case 3:    //Checkout a book : get name
                    if (name.Contains(user.Name) && user.Good)
                    {
                        ManageBooks.CheckOut(books, userBooks);
                    }
                    else
                    {
                        Console.WriteLine("Sorry " + user.Name + " but you have to pay your late fees before you check out a new book.");
                    }
                    break;

                case 4:    //Return a book: get name
                    user = ManageBooks.Return(books, user);
                    break;

                case 5:    //Search
                           //Search by author

                    //Search by about

                    //Search keyword
                    break;

                case 6:     //User acount details: book fees, checkout status, and current books checked out
                    Console.WriteLine("\n" + user.Name + " Account\n***************\n" +
                                      "\n| Can Checkout: " + user.Good + "\n| Fees: " + user.LateFee + "\n| Books Out - - - - - - - - - - - v");
                    if (userBooks != null)
                    {
                        foreach (Book book in userBooks)
                        {
                            Console.WriteLine("| Book : " + book.Title + " by " + book.Author + ". Due back: " + book.Due.Month + "-" + book.Due.Day + "-" + book.Due.Year);
                        }
                    }
                    if (!user.Good)
                    {
                        Console.WriteLine("Would you like to pay your late fee of " + user.LateFee + "  [ Y ]  [ N ]");
                        if (Console.ReadLine().ToLower() == "y")
                        {
                            user.LateFee = 0;
                            user.Good    = true;
                            Console.WriteLine("Thank you for taking care of that, now you can checkout books.");
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }