コード例 #1
0
        /// <summary>
        /// Allows admin user to update an existing category
        /// </summary>
        /// <param name="adminId"></param>
        private void UpdateCategory(int adminId)
        {
            new Book().ViewAllCategories();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var categoryId = InputHelper.ParseInput();

            if (categoryId == 0)
            {
                return;
            }

            AdminView.UpdateCategoryPage();
            var genere = Console.ReadLine();

            if (genere != "")
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.UpdateCategory(adminId, categoryId, genere);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
コード例 #2
0
        /// <summary>
        /// Allows an admin user to update an existing book
        /// </summary>
        /// <param name="adminId"></param>
        private void UpdateBook(int adminId)
        {
            new Book().FindAllAvailableBooks();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var bookId = InputHelper.ParseInput();

            if (bookId == 0)
            {
                return;
            }

            AdminView.UpdateBookPage();
            var title  = Console.ReadLine();
            var author = Console.ReadLine();
            var price  = InputHelper.ParseInput();

            if (title != "" && author != "" && price != 0)
            {
                WebbShopAPI api    = new WebbShopAPI();
                bool        result = api.UpdateBook(adminId, bookId, title, author, price);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
コード例 #3
0
        /// <summary>
        /// Allows admin user to set the amount of a book
        /// </summary>
        /// <param name="adminId"></param>
        private void SetAmount(int adminId)
        {
            new Book().FindAllAvailableBooks();
            AdminView.SetAmountPage();
            MessageViews.DisplayReturnMessage();

            var bookId = InputHelper.ParseInput();

            if (bookId == 0)
            {
                return;
            }

            var newAmount = InputHelper.ParseInput();

            WebbShopAPI api    = new WebbShopAPI();
            bool        result = api.SetAmount(adminId, bookId, newAmount);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
コード例 #4
0
        /// <summary>
        /// Allows an admin user to add a book to category
        /// </summary>
        /// <param name="adminId"></param>
        private void AddBookToCategory(int adminId)
        {
            AdminView.AddBookCategory();
            new Book().SearchBooksByTitle();
            MessageViews.DisplaySelectMessage();
            var bookId = InputHelper.ParseInput();

            new Book().ViewAllCategories();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var categoryId = InputHelper.ParseInput();

            if (categoryId == 0)
            {
                return;
            }

            if (bookId != 0 && categoryId != 0)
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.AddBookToCategory(adminId, bookId, categoryId);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
コード例 #5
0
        /// <summary>
        /// Runs the purchase functionality page
        /// </summary>
        /// <param name="userId"></param>
        public void Run(int userId)
        {
            PurchaseViews.StartPage();

            bool keepGoing = true;

            while (keepGoing)
            {
                new Book().FindAllAvailableBooks();
                MessageViews.DisplaySelectMessage();
                MessageViews.DisplayReturnMessage();
                var bookId = InputHelper.ParseInput();
                if (bookId == 0)
                {
                    break;
                }

                PurchaseViews.DisplayPurchaseMeny();
                MessageViews.DisplayReturnMessage();
                var input = InputHelper.ParseInput();
                if (input == 0)
                {
                    break;
                }

                switch (input)
                {
                case 1:
                    ViewDetails(bookId);
                    break;

                case 2:
                    PurchaseBook(userId, bookId);
                    keepGoing = false;
                    break;

                default:
                    MessageViews.DisplayNonAvailableMessage();
                    break;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Allows admin user to demote another admin user
        /// </summary>
        /// <param name="adminId"></param>
        private void DemoteUser(int adminId)
        {
            ViewAllUsers(adminId);
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();
            var userId = InputHelper.ParseInput();

            if (userId == 0)
            {
                return;
            }

            WebbShopAPI api    = new WebbShopAPI();
            bool        result = api.Demote(adminId, userId);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }
            MessageViews.DisplayErrorMessage();
        }
コード例 #7
0
        /// <summary>
        /// Allows admin user to delete book category
        /// </summary>
        /// <param name="adminId"></param>
        private void DeleteCategory(int adminId)
        {
            new Book().ViewAllCategories();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var categoryId = InputHelper.ParseInput();

            if (categoryId == 0)
            {
                return;
            }

            WebbShopAPI api    = new WebbShopAPI();
            var         result = api.DeleteCategory(adminId, categoryId);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
コード例 #8
0
        /// <summary>
        /// Allows admin user to delete book
        /// </summary>
        /// <param name="adminId"></param>
        private void DeleteBook(int adminId)
        {
            new Book().FindAllAvailableBooks();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var bookId = InputHelper.ParseInput();

            if (bookId == 0)
            {
                return;
            }

            WebbShopAPI api    = new WebbShopAPI();
            bool        result = api.DeleteBook(adminId, bookId);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }

            MessageViews.DisplayErrorMessage();
        }