Пример #1
0
        /// <summary>
        /// Shows info about book and gives the user the options to buy or abort.
        /// </summary>
        /// <param name="user">Takes a user to be connected to purchase</param>
        /// <param name="book">Takes a book for obtaining the info shown.</param>
        internal static void ShowInfoAboutBook(User user, Book book)
        {
            var continueLoop = true;

            do
            {
                BookView.ShowInfoAboutBook(book);
                var input = SharedController.GetSearchInput();
                switch (input.ToLower())
                {
                case "j":
                    BuyBook(user, book);
                    continueLoop = false;
                    break;

                case "n":
                    continueLoop = false;
                    break;

                default:
                    SharedError.PrintWrongInput();
                    continueLoop = true;
                    break;
                }
            } while (continueLoop);
        }
Пример #2
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();
            }
        }
Пример #3
0
        /// <summary>
        /// Method for adding a category to database
        /// </summary>
        /// <param name="admin">Takes a user with admin priviliges</param>
        private static void AddCategory(User admin)
        {
            var continueLoop = true;

            do
            {
                Console.Clear();
                AdminView.AddCategory();
                var input = SharedController.GetSearchInput();
                if (SharedController.CheckIfNullOrEmptyOrWhiteSpace(input))
                {
                    SharedError.PrintWrongInput();
                    continueLoop = true;
                }
                else
                {
                    if (api.AddCategory(admin.Id, input))
                    {
                        SharedError.Success();
                    }
                    else
                    {
                        SharedError.Failed();
                    }
                    continueLoop = false;
                }
            } while (continueLoop);
        }
Пример #4
0
        /// <summary>
        /// Method for searching with keyword and getting a list of matching categories
        /// </summary>
        /// <returns>returns a list of matching categories for the search keyword</returns>
        private static List <BookCategory> SearchAndListCategories()
        {
            List <BookCategory> categories = new List <BookCategory>();

            BookView.SearchForCategory();
            var input = SharedController.GetSearchInput();

            categories = api.GetCategories(input);
            Console.Clear();
            if (categories.Count > 0)
            {
                SharedView.ListCategories(categories);
            }

            return(categories);
        }
Пример #5
0
        /// <summary>
        /// Search book from specific author
        /// </summary>
        /// <returns>Returns a abort message if aborted during search.
        /// Always returns a list with books, empty or not.</returns>
        internal static (string message, List <Book> listWithBooks) SearchBooksFromAuthor()
        {
            List <Book> listOfBooksFromAuthor = new List <Book>();
            WebShopApi  api = new WebShopApi();

            Console.Clear();
            BookView.SearchBooksFromAuthor();
            var searchKeyword = SharedController.GetSearchInput();

            if (searchKeyword.ToLower() == "x")
            {
                return("Avbrutet", listOfBooksFromAuthor);
            }
            listOfBooksFromAuthor = api.GetBooksByAuthor(searchKeyword);
            return("Sökresultat", listOfBooksFromAuthor);
        }
Пример #6
0
        /// <summary>
        /// Method for updating the category name of specified category
        /// </summary>
        /// <param name="admin">Takes a user with admin priviliges</param>
        /// <param name="bookCategory">Takes a book category to be updated</param>
        private static void UpdateCategory(User admin, BookCategory bookCategory)
        {
            AdminView.UpdateCategory(bookCategory.Name);
            var input = SharedController.GetSearchInput();

            if (SharedController.CheckIfNullOrEmptyOrWhiteSpace(input))
            {
                SharedError.UnChanged();
            }
            else
            {
                if (api.UpdateCategory(admin.Id, bookCategory.Id, input))
                {
                    SharedError.Success();
                }
                else
                {
                    SharedError.Failed();
                }
            }
        }
Пример #7
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);
            }
        }