Beispiel #1
0
        public void ChooseActionForCategories()
        {
            CategoryDal categoryDal = new CategoryDal();

            Console.Clear();
            Console.WriteLine("TABLE: CATEGORIES\n\n");
            Console.WriteLine("What action you want to choose?\n" +
                              "1. View all categories\n" +
                              "2. Get category by Id\n" +
                              "3. Get category by name of column\n" +
                              "4. Add category\n" +
                              "5. Edit info about category\n" +
                              "6. Delete category by Id\n" +
                              "7. Delete category by name of column\n" +
                              "8. Back to start menu");
            Console.Write("\nYour selection: ");

            string ch = Console.ReadLine();

            switch (ch)
            {
            case "1":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    categoryDal.PrintListOfCategories(categoryDal.GetAll());
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "2":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\nId: ");

                    int id = Convert.ToInt32(Console.ReadLine());
                    categoryDal.PrintCategory(categoryDal.GetById(id));
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "3":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    Console.WriteLine("Name of column: ");
                    string fieldName = Console.ReadLine();
                    Console.WriteLine("\nValue: ");
                    string text = Console.ReadLine();
                    categoryDal.PrintListOfCategories(categoryDal.GetByFieldName(fieldName, text));
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "4":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    Console.WriteLine("NAME: ");
                    string name = Console.ReadLine();

                    Console.WriteLine("DESCRIPTION: ");
                    string desc = Console.ReadLine();

                    Category category = new Category(name, desc);
                    categoryDal.Insert(category);

                    Console.WriteLine("Category succesfully inserted :)");
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "5":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n");

                    Console.WriteLine("Name of column (set): ");
                    string fieldName = Console.ReadLine();

                    Console.WriteLine("Value (set): ");
                    string text = Console.ReadLine();

                    Console.WriteLine("Name of column (condition): ");
                    string fieldCondition = Console.ReadLine();

                    Console.WriteLine("Value (condition): ");
                    string textCondition = Console.ReadLine();

                    categoryDal.UpdateByFieldName(fieldName, text, fieldCondition, textCondition);

                    Console.WriteLine("Category succesfully updated :)");
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "6":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\nId: ");
                    int id = Convert.ToInt32(Console.ReadLine());
                    categoryDal.DeleteById(id);

                    Console.WriteLine("Category succesfully deleted :)");
                    Console.ReadKey();
                    break;
                }

                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "7":
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("TABLE: CATEGORIES\n\n ");

                    Console.WriteLine("Name of column (condition): ");
                    string fieldCondition = Console.ReadLine();

                    Console.WriteLine("Value (condition): ");
                    string textCondition = Console.ReadLine();

                    categoryDal.DeleteByFieldName(fieldCondition, textCondition);

                    Console.WriteLine("Category succesfully deleted :)");
                    Console.ReadKey();
                    break;
                }
                finally
                {
                    Menu menu = new Menu();
                    menu.ChooseActionForCategories();
                }
            }

            case "8":
            {
                Menu menu = new Menu();
                menu.ChooseTable();
                break;
            }

            default:
                Console.WriteLine("Invalid selection. Please select 1, 2, 3, 4, 5, 6, 7 or 8.");
                break;
            }
        }