Exemple #1
0
        public InfoCommande GetBoisson(int badge)
        {
            InfoCommande cmd = new InfoCommande();

            cmd.BadgeId = badge;
            Console.WriteLine("              ********** Selectionnez votre boisson *********\n" +
                              "                            The      --> 1\n" +
                              "                            Cafe     --> 2\n" +
                              "                            Chocolat --> 3\n");

            int boisson = int.Parse(Console.ReadLine());

            Console.WriteLine("              ********** Selectionnez la quantite de sucre *********\n" +
                              "                            Sans_Sucre  --> 1\n" +
                              "                            Moyenne     --> 2\n" +
                              "                            Elevee      --> 3\n");

            int quantiteSucre = int.Parse(Console.ReadLine());

            Console.WriteLine("              ********** Utilisez-vous votre mug?! Y/N *********\n");

            string m   = Console.ReadLine().ToUpper();
            bool   mug = m == "Y" ? true : false;

            cmd.Boisson = (Boisson)boisson;
            cmd.Sucre   = (Quantite_Sucre)quantiteSucre;
            cmd.Mug     = mug;
            return(cmd);
        }
        static async void PrepareCommande(int badgeId)
        {
            SaisieCommande saisie = new SaisieCommande();

            cmd = saisie.GetBoisson(badgeId);
            Console.WriteLine(await GetCommande(cmd));
            Console.WriteLine("\nVotre boisson est prete veuillez la prendre");
        }
        static async Task <InfoCommande> ProposeCommadeAsync(int badgeId)
        {
            InfoCommande        commande = new InfoCommande();
            HttpResponseMessage response = await httpClient.PostAsJsonAsync(
                "api/MachineCafe/ProposingBoisson", badgeId);

            if (response.IsSuccessStatusCode)
            {
                commande = await response.Content.ReadAsAsync <InfoCommande>();
            }
            return(commande);
        }
        static async Task <string> GetCommande(InfoCommande commande)
        {
            HttpResponseMessage response = await httpClient.PostAsJsonAsync(
                "api/MachineCafe/ServirBoisson", commande);

            if (response.IsSuccessStatusCode)
            {
                string result = await response.Content.ReadAsAsync <string>();

                return(result);
            }
            return(null);
        }
        public static async Task TraitementAsync()
        {
            try
            {
                Console.WriteLine("\nAvez-vous un badge !? Y/N");
                string commandeBadge = Console.ReadLine().ToUpper();

                if (commandeBadge == "Y")
                {
                    Console.WriteLine("\nVeuillez saisir le numero de votre Badge");

                    int badge = int.Parse(Console.ReadLine());

                    cmd = await ProposeCommadeAsync(badge);

                    if (cmd != null)
                    {
                        string mug = cmd.Mug == true ? "Avec votre Mug" : "Sans votre Mug";

                        Console.WriteLine("\nDesirez vous prendre un " + cmd.Boisson + ", quantite_Sucre " + cmd.Sucre + " , " + mug + " ?!  Y/N");

                        string choix = Console.ReadLine().ToUpper();

                        if (choix == "Y")
                        {
                            Console.WriteLine(await GetCommande(cmd));
                            Console.WriteLine("\nVotre boisson est prete veuillez la prendre");
                        }

                        else
                        {
                            PrepareCommande(badge);
                        }
                    }

                    else
                    {
                        PrepareCommande(badge);
                    }
                }
                else
                {
                    PrepareCommande(0);
                }
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }