public static string Pushtocache(string strJson, string name)
 {
     if (Globalmemorycache.isExist(name))
     {
         strJson = Globalmemorycache.GetItem(name).ToString();
     }
     else
     {
         Globalmemorycache.AddItem(name, strJson);
     }
     return(strJson);
 }
Esempio n. 2
0
        public void OutputAllProduct(string strJson)
        {
            //Check memory cache if exist or not
            strJson = Globalmemorycache.Pushtocache(strJson, "Products");

            //Manage Json file : From Interface to Class, cant Parse ProductDto as List.. Need to, to access Properties value in json.
            var products = JsonConvert.DeserializeObject <List <ProductDto> >(strJson);

            int cntr = 1;

            foreach (var prod in products)
            {
                Console.WriteLine($"\n\n{cntr})ProductID: {prod.Id}\t\tProduct Name:{prod.ProductName}\tCategory ID:{prod.CategoryId}\t  Price:{Formatcurrencyprice(prod.Price)}\nProperties:");
                foreach (var prop in prod.Properties)
                {
                    Console.WriteLine($"\tKeyName: {prop.KeyName}\t\tValue: {prop.Value}");
                }
                cntr++;
            }
            // end Managing json file
        }
Esempio n. 3
0
        public void OutputProductGroupedByPriceSegment(string strJson)
        {
            // by 100

            //Check memory cache if exist or not
            strJson = Globalmemorycache.Pushtocache(strJson, "Products");
            //Manage Json file : From Interface to Class, cant Parse ProductDto as List.. Need to, to access Properties value in json.
            var products = JsonConvert.DeserializeObject <List <ProductDto> >(strJson);

            SorfbyPrice sortbyprice = new SorfbyPrice();

            products.Sort(sortbyprice);

            int CurrentHeaderFrmValue = -1;

            foreach (var prod in products)
            {
                int HeaderFromValue, HeaderToValue = 0;
                SetCurrencyValue(prod.Price);                                               // check / Get the selected price on  current currency selected
                HeaderFromValue = GetWholenumber(CurrencyInfo.SelectedCurrencyPrice) * 100; //frm
                HeaderToValue   = HeaderFromValue + 100;                                    // to

                if (CurrentHeaderFrmValue != HeaderFromValue)
                {
                    //display
                    Console.WriteLine($"\n\n{HeaderFromValue} - {GetformatHeader(HeaderToValue)}");

                    //child
                    var currentcurrencyvalue = Formatcurrencyprice(prod.Price); //with value sign
                    Console.WriteLine($"\t{prod.ProductName}\t{currentcurrencyvalue}");
                    CurrentHeaderFrmValue = HeaderFromValue;
                }
                else
                {                                                               //child
                    var currentcurrencyvalue = Formatcurrencyprice(prod.Price); //with value sign
                    Console.WriteLine($"\t{prod.ProductName}\t{currentcurrencyvalue}");
                }
            }
        }
        static void Main(string[] args)
        {
            var container             = new Container(new DefaultRegistry());
            var productListVisualizer = container.GetInstance <ProductListVisualizer>();

            // Load json file and Store to cache
            Console.WriteLine("Loaded Json file and Added to cache.\n");
            var strJson = Globalmemorycache.Pushtocache(GetStrJson(), "Products");

            //Currency Selection
            DisplayCurrenctyOptions();
            CheckSelectedCurrency();


            //Product Selection
            DisplayProductOption();
            ProductOption(productListVisualizer, strJson, true);


            Console.Write("\n\rPress any key to exit!");
            Console.ReadKey();
        }
Esempio n. 5
0
        public void OutputPaginatedProducts(string strJson, int numberofpages)
        {
            //Check memory cache if exist or not
            strJson = Globalmemorycache.Pushtocache(strJson, "Products");
            //Manage Json file :
            var products = JsonConvert.DeserializeObject <List <ProductDto> >(strJson);

            decimal maxpage        = products.Count / numberofpages;
            int     selectedpage   = 1;
            int     endingpage     = 0;
            string  endpageCaption = string.Empty;

Executepage:
            int cntr = 0;

            endingpage = selectedpage * (int)maxpage;

            endpageCaption = selectedpage.ToString();
            if (selectedpage == maxpage)
            {
                endpageCaption = " END";
            }

            Console.WriteLine($"\nPage :  {endpageCaption}");
            foreach (var prod in products)
            {
                if (cntr >= (endingpage - 5) && cntr < endingpage)
                {
                    Console.WriteLine($"\nProductID: {prod.Id}\t\tProduct Name: {prod.ProductName}\tCategory ID: {prod.CategoryId}\tPrice: {Formatcurrencyprice(prod.Price)}\nProperties:");
                    foreach (var prop in prod.Properties)
                    {
                        Console.WriteLine($"\tKeyName: {prop.KeyName}\t\tValue: {prop.Value}");
                    }

                    if (cntr == endingpage - 1)
                    {
                        break;
                    }
                }
                cntr++;
            }
            if (selectedpage <= numberofpages)  //remove last page null
            {
                Console.WriteLine("\n\t\tEND OF PAGE: " + selectedpage);

                //console key
                Console.Write("\n\n  BACK [<<]   [>>] NEXT \n");
                var input = Console.ReadKey();

                switch (input.Key)
                {
                case ConsoleKey.LeftArrow:
                    if (selectedpage > 1)
                    {
                        selectedpage--;
                        Console.Write($"\n\n\n\n\t\t\tYou are in Page #: {selectedpage}\n");
                        goto Executepage;
                    }

                    break;

                case ConsoleKey.RightArrow:
                    selectedpage++;
                    if (selectedpage < maxpage)
                    {
                        Console.Write($"\n\n\n\n\t\t\tYou are in Page #: {selectedpage}\n");
                    }
                    goto Executepage;



                case ConsoleKey.Q:

                    break;

                default:
                    Console.WriteLine("\nInvalid option!");
                    break;
                }
            }



            Console.WriteLine();
        }