Beispiel #1
0
        public void makeLoan()
        {
            //Creating a Loan ID. This checks against all of the current Loans, and ensures that an ID isn't used more than once.
            int i = 1;

            foreach (Loans loan in lib.GetLoans())
            {
                i++;
            }
            int loanID = i;

            //Getting the Relevant Details to construct a new Loan Object
            Console.WriteLine("Please enter the ID of the Customer making the Loan: ");
            int loanCustID; //For an integer entry, we ensure that the given data is an Integer, and doesn't proceed until an Integer is given

            while (!int.TryParse(Console.ReadLine(), out loanCustID))
            {
                Console.WriteLine("\nThe Value you've entered isn't a number, please try again.");
                Console.WriteLine("Please enter the ID of the Customer making the Loan: ");
            }

            Console.WriteLine("\nPlease enter the title of the book to be Loaned: ");
            string loanBookTitle = Console.ReadLine();

            //Here we get the Amount of Days which the book is to be loaned for, which gives the User Flexibility of the Loans being issued.
            Console.WriteLine("\nPlease enter the amount of days that the book is to be loaned for: ");
            int lengthOfLoan;

            while (!int.TryParse(Console.ReadLine(), out lengthOfLoan))
            {
                Console.WriteLine("\nThe Value you've entered isn't a valid number, please try again.");
                Console.WriteLine("\nPlease enter the amount of days that the book is to be loaned for: ");
            }

            //Here we are using the DateTime Method to add Days of the loan Length to nows date, to provide us with the
            string returnDate = DateTime.Now.AddDays(lengthOfLoan).ToString("dd/MM/yy");

            //Outputting the Final Loan Details before submitting the Loan to the Loan Object List
            Console.WriteLine("\nThanks, the new Loan is as follows");
            Console.WriteLine("LoanID: {0}\nCustomer ID of Loan: {1}\nTitle of the Book being Loaned: {2}\nReturn due of the Book being Loaned: {3}\n",
                              loanID, loanCustID, loanBookTitle, returnDate);

            //Creating a new Loan Object based upon the information given above.
            var loan1 = new Loans(lib, loanID, loanBookTitle, loanCustID, returnDate);

            //Adding the Loan Object to the Loans List through the Library Method.
            lib.AddLoans(loan1);
            Menu();
        }
Beispiel #2
0
 public void AddLoans(Loans loan)
 {
     loans.Add(loan); //Add the loan to the loans list
     //Loan Details are obtained from the Constructor in the Loans Class
     //Constructor creates Loan Objects, the createCustomer Method inputs the information for the Object, and submits it to the list
 }