}//END AddToLIbrary // Returns a list of items from a particular dictionary (library subset) in the library as is. Used primarily for display in the GUI. // Since working with a dictionary the order is never certain and must be handled at a later time to ensure consistent output. public List <DispListObject> GetLibrarySubset(whichLibrary subsetToRetrieve) { List <DispListObject> tempList = new List <DispListObject>(); Dictionary <string, Book> tempDictionaryRef; // Make an internal reference variable to capture the dictionary to avoid code duplication later DispListObject bookFromDictionary; // An internal instance of the abbreviated book details used for list display in the GUI if (subsetToRetrieve == whichLibrary.Owned) // Choose the proper library subset to access { tempDictionaryRef = ownedLib; } else if (subsetToRetrieve == whichLibrary.Wishlist) { tempDictionaryRef = wishlistLib; } else { tempDictionaryRef = null; Console.WriteLine("There was an error in assigning the dictionary in the library. An invalid or empty library name was used!"); } foreach (KeyValuePair <string, Book> entry in tempDictionaryRef) // for each book in the subset get the details needed for a list display { // then add it to the current list tempList.Add(bookFromDictionary = new DispListObject(entry.Value)); } return(tempList); }//END GetLibrarySubset
}//END Library CONSTRUCTOR public void AddToLibrary(Book newBook, whichLibrary libraryToUse) { if (libraryToUse == whichLibrary.Wishlist) { wishlistLib.Add(newBook.getISBN(), newBook); } else if (libraryToUse == whichLibrary.Owned) { ownedLib.Add(newBook.getISBN(), newBook); } else { Console.WriteLine("There was an error with determining which library to add the book to!"); // Add series option as additonal step here once feature is added // The console output will need to be updated to display a popup window to notify user after testing } }//END AddToLIbrary
}//END OwnedTotal public Book GetBookFromLib(whichLibrary currLibView, string currBookKey) { Book foundBook; /* This will need to be modified to do a "TryGet" check later to handle cases where the ID does not exist */ if (currLibView == whichLibrary.Owned) { foundBook = ownedLib[currBookKey]; } else if (currLibView == whichLibrary.Wishlist) { foundBook = wishlistLib[currBookKey]; } else { foundBook = null; Console.WriteLine("There was an error getting the book specified... Sure would be nice to have that try get check!"); } return(foundBook); }//END GetBookFromLib