예제 #1
0
        // Finds the specified Item within the Library's Catalog and checks to see if it is available to be checked out.
        // If available, the Item's status is changed to CheckedOut, and their DueDate value is changed to 14 days following the current date/time.
        // If it is already checked out, the console states that the item is not available.
        public void Checkout(List <Item> itemsList)
        {
            Console.Clear();
            for (int i = 0; i < itemsList.Count; i++)
            {
                Console.Write($"Item {i + 1}. ");
                itemsList[i].PrintInfo();
                Console.WriteLine();
            }
            string input = CnslFormatter.PromptForInput($"Please select the item you would like to checkout. [{CnslFormatter.MoreThanOne(itemsList)}]: ");

            if (Int32.TryParse(input, out int num))
            {
                int index = num - 1;

                if (index < 0 || index >= itemsList.Count)
                {
                    Console.WriteLine($"Input out of range. {CnslFormatter.MoreThanOne(itemsList)}.");
                }
                else
                {
                    if (itemsList[index].Status == ItemStatus.OnShelf)
                    {
                        Console.WriteLine(Environment.NewLine + "You have checked out: ");
                        Console.WriteLine($"   {itemsList[index].Title} by {itemsList[index].Author}");
                        DateTime checkoutDate = DateTime.Now;
                        itemsList[index].Status  = ItemStatus.CheckedOut;
                        itemsList[index].DueDate = checkoutDate.AddDays(14);
                        Console.WriteLine($"   Due back by {itemsList[index].DueDate:d}");
                        CnslFormatter.PauseByAnyKey();
                    }
                    else if (itemsList[index].Status == ItemStatus.CheckedOut || itemsList[index].Status == ItemStatus.Overdue)
                    {
                        Console.WriteLine("\nItem is already checked out. Cannot complete checkout at this time.");
                        CnslFormatter.PauseByAnyKey();
                    }
                    else
                    {
                        Console.WriteLine("\nCannot complete checkout at this time.");
                        CnslFormatter.PauseByAnyKey();
                    }
                }
            }
            else
            {
                Console.WriteLine("\nNon-Integer input detected. Please enter an integer next time.");
            }
        }
예제 #2
0
        // Finds the specified Item within the Library's Catalog and checks to see if it is checked out to then be checked back in.
        // If checked out, the Item's status is changed to OnShelf (checked in).
        // If it is already checked in, the console states that the item is already checked in.
        public void CheckIn(List <Item> itemsList)
        {
            bool proceed = CnslFormatter.AskYesOrNo($"Would you like to return an item? ");

            while (proceed)
            {
                Console.Clear();
                for (int i = 0; i < itemsList.Count; i++)
                {
                    Console.Write($"Item {i + 1}. ");
                    itemsList[i].PrintInfo();
                    Console.WriteLine();
                }
                string input = CnslFormatter.PromptForInput($"Please select the item you would like to return? [{CnslFormatter.MoreThanOne(itemsList)}]: ");
                if (Int32.TryParse(input, out int num))
                {
                    int index = num - 1;

                    if (index < 0 || index >= itemsList.Count)
                    {
                        Console.WriteLine($"Input out of range. {CnslFormatter.MoreThanOne(itemsList)}.");
                    }
                    else
                    {
                        if (itemsList[index].Status == ItemStatus.CheckedOut || itemsList[index].Status == ItemStatus.Overdue)
                        {
                            Console.WriteLine(Environment.NewLine + "You have checked in: ");
                            Console.WriteLine($"   {itemsList[index].Title} by {itemsList[index].Author}");
                            itemsList[index].Status = ItemStatus.OnShelf;
                            proceed = false;
                        }
                        else
                        {
                            Console.WriteLine("Cannot complete checkout at this time.");
                            CnslFormatter.PauseByAnyKey();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Non-Integer input detected. Please enter an integer.");
                }
            }
            CnslFormatter.PauseByAnyKey();
        }