示例#1
0
        /// <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();
            }
        }
示例#2
0
        /// <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);
                }
            }
        }
示例#3
0
        /// <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);
            }
        }
示例#4
0
 /// <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);
     }
 }