예제 #1
0
        /// <summary>
        /// Delete category (if empty)
        /// </summary>
        /// <param name="admin">Takes a user with admin priviliges</param>
        private static void DeleteCategory(User admin)
        {
            var continueLoop = true;

            do
            {
                Console.Clear();
                AdminView.DeleteCategory();
                var categories = api.GetCategories();
                SharedView.ListCategories(categories);
                var input = SharedController.GetAndValidateInput();
                if (input.validatedInput > 0 &&
                    input.validatedInput <= categories.Count)
                {
                    if (api.DeleteCategory(
                            admin.Id,
                            categories[input.validatedInput - 1].Id))
                    {
                        SharedError.Success();
                    }
                    else
                    {
                        var books = api.GetBooksInCategory(categories[input.validatedInput - 1].Id);
                        SharedError.BooksStillInCategory(books.Count);
                    }
                }
                else
                {
                    if (input.validatedInput == 0 &&
                        input.menuInput.ToLower() == "x")
                    {
                        continueLoop = false;
                    }
                    else
                    {
                        SharedError.PrintWrongInput();
                    }
                }
            } while (continueLoop);
        }