/// <summary> /// Method for searching for specified user /// </summary> /// <param name="admin">Takes a user with admin priviliges</param> private static void SearchForUser(User admin) { AdminView.SearchForUser(admin); var searchKeyword = SharedController.GetSearchInput(); var listWithUsers = api.FindUser(admin.Id, searchKeyword); if (listWithUsers.Count > 0) { var continueLoop = true; do { AdminView.ListAllUsers(listWithUsers); var input = SharedController.GetAndValidateInput(); if (input.validatedInput == 0 || input.validatedInput > listWithUsers.Count) { SharedError.PrintWrongMenuInput(); } else { EditUser(admin, listWithUsers[input.validatedInput - 1]); continueLoop = false; } } while (continueLoop); } else { SharedError.NothingFound(); } }
/// <summary> /// Search and buy a book by category listing /// </summary> /// <param name="user">Takes a user to be connected with the purchase</param> internal static void BuyByChooseByCategory(User user) { var categories = FindAndListCategories(); var chosenCategory = ChooseCategoryToView(categories); var books = api.GetBooksInCategory(chosenCategory.Id); if (books.Count == 0) { SharedError.NothingFound(); } else { var book = ListAndChooseBook(books); if (book != null) { ShowInfoAboutBook(user, book); } } }
/// <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); } }