Exemple #1
0
        static beersInfo.RootObject getBeerInfo(string link)
        {
            RootObject obj1 = new RootObject();
            string     realLink;

            realLink = "http://datc-rest.azurewebsites.net" + link;

            hal halObj = new Client.hal();
            var client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/hal+json"));
            var response = client.GetAsync(realLink).Result;

            var data = response.Content.ReadAsStringAsync().Result;

            //Console.WriteLine(data); // afisarea json-ului ajuta la determinarea clasei cu ajutorul [email protected]
            beersInfo.RootObject x = JsonConvert.DeserializeObject <beersInfo.RootObject>(data);

            // Console.WriteLine(data);
            return(x);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            RootObject obj1    = new RootObject();
            int        opt     = -10;
            int        meniu   = 0;
            string     linkGet = "/breweries";

            hal.RootObject x;
            x = getBeerFromStr(linkGet);

            Console.WriteLine(x._embedded.brewery[0].Name);

            // while (opt != -10)
            // {
            int men1 = 0;

            do
            {
                do
                {
                    Console.WriteLine("Alegeti actiunea ce doriti sa o efectuati:");
                    Console.WriteLine("1 : Parcurge beri");
                    Console.WriteLine("2 : Adauga beri");
                    Console.WriteLine("3 : Exit");
                    men1 = Int32.Parse(Console.ReadLine());
                } while (men1 == 0 || men1 < 1 || men1 > 3); // oblig utilizatorul sa introduca o optiune valida

                if (men1 == 3)
                {
                    Console.WriteLine("Exit!");
                    return;
                }
                else
                if (men1 == 2)                                     // Am ales sa adaug beri
                {
                    beers.RootObject a = postJson(0, "0", "0", 0); // obtinerea json-ului nemodificat

                    for (int i = 0; i < a._embedded.beer.Count(); i++)
                    {
                        Console.WriteLine(i + " : " + a._embedded.beer[i].Name);
                    }

                    introdBere();
                    Console.WriteLine("0 : Inapoi");
                    Console.WriteLine("1 : Exit");
                    Console.WriteLine("2 : Introduceti alta bere");

                    int men2 = Int32.Parse(Console.ReadLine());

                    if (men2 == 1)
                    {
                        Console.WriteLine("Exit");
                        return;
                    }
                    else
                    {
                        men1 = men2;
                    }
                }
                else
                if (men1 == 1)
                {
                    do
                    {
                        Console.WriteLine();
                        Console.WriteLine("Alegeti un tip de bere din cele de mai jos: ");

                        for (int i = 0; i < x._embedded.brewery.Count; i++)
                        {
                            string s  = "";
                            int    i2 = i;
                            s = s + (i2 + 1) + ": ";
                            s = s + x._embedded.brewery[i].Name;

                            Console.WriteLine(s);
                        }
                        Console.WriteLine("0 : Exit");
                        Console.WriteLine();

                        opt = Int32.Parse(Console.ReadLine());
                        Console.WriteLine(opt);
                        if (opt == 0 || opt < 0)
                        {
                            return;
                        }
                        else
                        if ((opt < x._embedded.brewery.Count) && (x._embedded.brewery[opt - 1]._links != null))
                        {
                            string link1 = x._embedded.brewery[opt - 1]._links.beers.href;
                            Console.WriteLine(link1);
                            SecondLink.RootObject NewStringBeers;
                            NewStringBeers = getBeerFromStr2(link1);

                            for (int i = 0; i < NewStringBeers._embedded.beer.Count; i++)
                            {
                                string s = "";
                                s = s + i + ": ";
                                s = s + NewStringBeers._embedded.beer[i].Name;

                                Console.WriteLine(s);
                            }
                            Console.WriteLine();
                            Console.WriteLine("Alegeti berea despre care doriti informatii:");
                            int informatii = Int32.Parse(Console.ReadLine());

                            if (informatii < NewStringBeers._embedded.beer.Count)
                            {
                                beersInfo.RootObject info = getBeerInfo(NewStringBeers._embedded.beer[informatii]._links.brewery.href);
                                Console.WriteLine("ID : " + info.Id + " Name " + info.Name);
                                Console.WriteLine();
                            }
                            else
                            {
                                Console.WriteLine("Valoarea nu este dintre cele din lista\n");
                                Console.WriteLine();
                            }
                        }
                        else
                        {
                            if (opt >= x._embedded.brewery.Count)
                            {
                                Console.WriteLine("In afara optiunilor\n");
                                Console.WriteLine();
                            }
                            else if (opt == -1)
                            {
                                Console.WriteLine("Exit!\n");
                                Console.WriteLine();
                            }
                        }
                    } while (opt != -1);
                }
                Console.WriteLine("Gata!");
            } while (men1 != 3);

            Console.ReadLine();
        }