public static CatalogService getInstance() { if (instance == null) { instance = new CatalogService(); } return(instance); }
public static void RedirectUser(string userOption) { string retrievedISBN; string retrievedTitle; List <Author> retrievedAuthors; List <KeyValuePair <string, Book> > listOfBooks; switch (userOption) { case "1": retrievedISBN = getISBN(); retrievedTitle = getTitle(); retrievedAuthors = getAuthors(); CatalogService.getInstance().AddBookToCatalog(retrievedISBN, new Book(retrievedTitle, retrievedAuthors)); break; case "2": retrievedISBN = getISBN(); CatalogService.getInstance().RemoveBookFromCatalog(retrievedISBN); break; case "3": string retrievedAuthorFullName = getOneAuthor(); listOfBooks = CatalogService.getInstance().FindBookByAuthor(new Author(retrievedAuthorFullName)); Console.WriteLine($"\nWyniki wyszukiwania:\n"); foreach (KeyValuePair <string, Book> book in listOfBooks) { Console.WriteLine($"\n{book.Value}"); Console.WriteLine($"Numer ISBN: {book.Key}\n"); } break; case "4": retrievedTitle = getTitle().ToLower(); listOfBooks = CatalogService.getInstance().FindBookByTitle(retrievedTitle); Console.WriteLine($"\nWyniki wyszukiwania:\n"); foreach (KeyValuePair <string, Book> book in listOfBooks) { Console.WriteLine($"\n{book.Value}"); Console.WriteLine($"Numer ISBN: {book.Key}\n"); } break; case "5": retrievedISBN = getISBN(); var FoundBook = CatalogService.getInstance().FindBookByISBN(retrievedISBN); Console.WriteLine($"\nWyniki wyszukiwania:\n"); Console.WriteLine(FoundBook); Console.WriteLine($"Numer ISBN: {retrievedISBN}\n"); break; case "6": Console.WriteLine("\nPodaj liczbę tygodni:"); int numberOfWeeksWithoutBorrowing = int.Parse(Console.ReadLine()); listOfBooks = CatalogService.getInstance().FindBooksUnborrowedByNWeeks(numberOfWeeksWithoutBorrowing); Console.WriteLine($"\nKsiążki, które nie zostały wypożyczone przez {numberOfWeeksWithoutBorrowing} tyg.: \n"); foreach (KeyValuePair <string, Book> book in listOfBooks) { Console.WriteLine($"{book.Value}, ostatnia data wypożyczenia to:{book.Value.LastBorrowDate}"); Console.WriteLine($"Numer ISBN: {book.Key}\n"); } break; case "7": retrievedISBN = getISBN(); Console.WriteLine("Podaj swoje imie i nazwisko:\n"); string customerFullName = Console.ReadLine(); string[] customerData = splitText(customerFullName); CatalogService.getInstance().BorrowBook(retrievedISBN, new Customer(customerData[0], customerData[1])); break; case "8": Console.WriteLine("\n** Osoby posiadające aktualnie wypożyczone książki to: \n"); var listOfCustomersWithBorrowedBooks = CatalogService.getInstance().FindCustomersWithBorrowedBooks(); foreach (Customer customer in listOfCustomersWithBorrowedBooks) { Console.WriteLine(customer.ToString()); } break; case "q": Console.WriteLine("\n******************************************"); Console.WriteLine("Dziękujemy za skorzystanie z biblioteki"); isReadyToQuit = true; return; default: Console.WriteLine("\nNie ma takij opcji. Aby wybrać jedną z opcji wpisz cyfrę 1-8 lub 'q' jeżli chcesz wyjść. "); break; } }