Ejemplo n.º 1
0
        static void GetProductByCategory()
        {
            int selectInt;

            #region menu
            Console.WriteLine("Seçmek istediyiniz kategoriyanin nomresini qeyd edin");

            Console.WriteLine("1 - Ichkiler");
            Console.WriteLine("2 - Meyveler");
            Console.WriteLine("3 - Yaglar");
            Console.WriteLine("4 - UnMehsullari");
            Console.WriteLine("5 - Terevezler");
            Console.WriteLine("6 - Shokoladlar");
            Console.WriteLine("0 - Geri qayitmaq");

            string select = Console.ReadLine();

            Product product = new Product();

            while (!int.TryParse(select, out selectInt))
            {
                Console.WriteLine("Rəqəm daxil etməlisiniz");
                select = Console.ReadLine();
            }
            #endregion
            #region Menu Select
            switch (selectInt)
            {
            case 1:
                product.Category = Category.Ichkiler;
                break;

            case 2:
                product.Category = Category.Meyveler;
                break;

            case 3:
                product.Category = Category.Yaglar;
                break;

            case 4:
                product.Category = Category.UnMehsullari;
                break;

            case 5:
                product.Category = Category.Terevezler;
                break;

            case 6:
                product.Category = Category.Shokoladlar;
                break;

            case 0:
                break;

            default:
                Console.WriteLine("1-6 arasi reqem daxil edilmelidir");
                break;
            }
            if (selectInt >= 1 && selectInt <= 6)
            {
                var list = marketableService.GetProductByCategory(product.Category);
                if (list.Count == 0)
                {
                    Console.WriteLine("Bu kateqoriyaya uygun mehsul yoxdur");
                }
                else
                {
                    var table = new ConsoleTable("Mehsul", "Mehsulun adi", "Mehsulun Kodu", "Mehsulun sayi", "Mehsulun qiymeti", "Mehsulun Kateqoriyasi");
                    int i     = 1;
                    foreach (var item in list)
                    {
                        _ = table.AddRow(i, item.ProductName, item.ProductCode, item.ProductCount, item.ProductPrice, item.Category);
                        i++;
                    }

                    table.Write();
                }
            }
            #endregion
        }