/// <summary> /// Method for getting input and searching for a book /// </summary> /// <returns>A specific book</returns> public static Book SearchForBook() { WebShopApi api = new WebShopApi(); Console.Clear(); BookView.SearchForBook(); var searchKeyword = SharedController.GetSearchInput(); if (searchKeyword.ToLower() == "x") { return(null); } var listWithMatchingBooks = api.GetBooks(searchKeyword); if (listWithMatchingBooks.Count > 0) { Console.Clear(); BookView.ListAllBooks(listWithMatchingBooks); var input = SharedController.GetAndValidateInput(); if (input.validatedInput != 0 && input.validatedInput <= listWithMatchingBooks.Count) { return(api.GetBook(listWithMatchingBooks[input.validatedInput - 1].Id)); } else { SharedError.PrintWrongInput(); return(null); } } else { SharedError.NothingFound(); return(null); } }
/// <summary> /// List all books and choose one to return /// </summary> /// <param name="listWithMatchingBooks">Takes a list of books</param> /// <returns>returns a book</returns> internal static Book ListAndChooseBook(List <Book> listWithMatchingBooks) { if (listWithMatchingBooks.Count > 0) { Console.Clear(); BookView.ListAllBooks(listWithMatchingBooks); var input = SharedController.GetAndValidateInput(); if (input.validatedInput != 0 && input.validatedInput <= listWithMatchingBooks.Count) { return(api.GetBook(listWithMatchingBooks[input.validatedInput - 1].Id)); } else { SharedError.PrintWrongInput(); return(null); } } else { SharedError.NothingFound(); return(null); } }