Esempio n. 1
0
        static bool addLoan() //Method to add a new loan to the system
        {
            Console.Write("Book being Loaned: ");
            string loanBook = Console.ReadLine().ToUpper();   //Book to be loaned
            bool   loaned   = BookDetails.isLoaned(loanBook); //checks if book is currently loaned

            string[] loanCustomer = new string[2];
            Console.WriteLine("Who is Loaning the book?");
            Console.Write("First Name: ");
            loanCustomer[0] = Console.ReadLine().ToUpper();
            Console.Write("Surname: ");
            loanCustomer[1] = Console.ReadLine().ToUpper();
            bool customerMatch = CustomerDetails.lookupCustomer(loanCustomer); //Checks if customer is registered on the system

            string   currentEmployee = LoginDetails.currentUser();             //Saves current user as employee loaning the book
            DateTime loanOut;

            loanOut = DateTime.Now; //Sets current date as when the book is loaned
            string loanoutString = loanOut.ToShortDateString();

            DateTime loanIn       = loanOut.AddDays(21); //Generates a date for when the book needs to be returned
            string   loaninString = loanIn.ToShortDateString();

            string newID = Guid.NewGuid().ToString(); //Generates a unique 5 digit ID for the loan as refrence

            char[] idCharacters = newID.Take(5).ToArray();
            newID = new string(idCharacters);

            if (loaned)                                              //if the book is already loaned
            {
                Console.WriteLine("Error | Book is Already Loaned"); //Display error message and abort the method
                return(false);
            }
            if (customerMatch == false)                               //If loan customer is not registered on the system
            {
                Console.WriteLine("Error | Customer not Registered"); //Display error message and abort the loan
                return(false);
            }

            string[] loanString = new string[] { loanBook, loanCustomer[1], loanCustomer[0], currentEmployee, loanoutString, loaninString };
            loanRecords.Add(newID, loanString); //Add new loan to the system
            loanedBooks.Add(loanBook);          //Add loaned book to list of books currently loaned
            Console.WriteLine("Book Succesfully Loaned");
            return(true);
        }