Пример #1
0
        public static void InsertIntoCart(LuisResponse Data, IDialogContext context)
        {
            try
            {
                for (int i = 0; i < Data.entities.Length; i++)
                {
                    // dish dish1 = new dish();
                    Cart cart = new Cart();

                    if (i == 0 && !(Data.entities[i].type.Equals("builtin.number")))
                    {
                        cart.Quantity = 1;
                    }
                    else if (i != 0 && !(Data.entities[i].type.Equals("builtin.number")))
                    {
                        cart.Quantity = 1;

                        //i++
                    }
                    else
                    {
                        cart.Quantity = Convert.ToInt32(Data.entities[i].entity.ToString());
                        i++;
                    }
                    cart.ProductName = Data.entities[i].entity.ToString();
                    cart.Price       = Convert.ToInt32(SQLManager.GetItems(cart.ProductName));
                    CartList.Add(cart);

                    //cart.ProductName = Data.entities[i].entity.ToString();
                    //CartList.Add(cart);
                }
                //for (int i = 0; i <CartList.Count; i++)
                //{
                //    context.PostAsync("Food Item: " + CartList[i].ProductName + " Price : " +CartList[i].Price + " Quantity : " + CartList[i].Quantity);
                //}
                for (int i = 0; i < CartList.Count; i++)
                {
                    TotalAmount = CartList[i].Price * CartList[i].Quantity;
                }

                //TotalAmount = Calculation.Calculate(CartList);

                //Modify(context);
                context.PostAsync($"Your Total Cost till now is : {TotalAmount}");
            }

            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var    option = await result as Activity;
            string choice = option.Text;

            //string choice2 = await choice.Text;
            RootDialog.newdishes.Add(choice);
            using (HttpClient httpClient = new HttpClient())
            {
                LuisResponse Data = new LuisResponse();
                try
                {
                    var responseInString = await httpClient.GetStringAsync(@"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/684384d6-f50b-4f66-b628-270bf84b2980?staging=true&verbose=true&timezoneOffset=-360&subscription-key=59e472415afd44a595605a762b8c81ab&q="
                                                                           + System.Uri.EscapeDataString(choice));

                    Data = JsonConvert.DeserializeObject <LuisResponse>(responseInString);

                    choice = null;
                    var intent = Data.topScoringIntent.intent;
                    var score  = Data.topScoringIntent.score;
                    Data.entities.OrderBy(o => o.startIndex);
                    if (intent == "SelectNonVegDishes" && score > 0.8)
                    {
                        foreach (var entity in Data.entities)
                        {
                            choice += entity.entity;

                            List <Cart> CartData = new List <Cart>();

                            context.ConversationData.TryGetValue("UserCart", out CartData);

                            CartData = LUIS.CartList;

                            context.ConversationData.SetValue("UserCart", CartData);
                        }
                        LUIS.InsertIntoCart(Data, context);
                        this.GoBack(context);
                    }
                    else

                    {
                    }
                }
                catch (Exception e)
                {
                    context.PostAsync("NonVegException");
                }
            }
        }
Пример #3
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            var    option = await result as Activity;
            string choice = option.Text;

            //string choice2 = await choice.Text;
            RootDialog.newdishes.Add(choice);
            using (HttpClient httpClient = new HttpClient())
            {
                LuisResponse Data = new LuisResponse();
                try
                {
                    var responseInString = await httpClient.GetStringAsync(@"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/684384d6-f50b-4f66-b628-270bf84b2980?staging=true&verbose=true&timezoneOffset=-360&subscription-key=59e472415afd44a595605a762b8c81ab&q="
                                                                           + System.Uri.EscapeDataString(choice));

                    Data = JsonConvert.DeserializeObject <LuisResponse>(responseInString);

                    choice = null;
                    var intent = Data.topScoringIntent.intent;
                    var score  = Data.topScoringIntent.score;
                    Data.entities.OrderBy(o => o.startIndex);
                    if (intent == "SelectVegDishes" && score > 0.8)
                    {
                        foreach (var entity in Data.entities)
                        {
                            choice += entity.entity;
                            // LUIS.InsertIntoCart(Data,context);

                            List <Cart> CartData = new List <Cart>();

                            context.ConversationData.TryGetValue("UserCart", out CartData);

                            CartData = LUIS.CartList;

                            context.ConversationData.SetValue("UserCart", CartData);

                            //  await this.MessageReceivedAsync(context,CartData);

                            // PromptDialog.Choice(context, CheckOut, new List<string>() { "Confirm Order", "Continue Ordering", "Remove from Cart" }, "Any thing else?", "Invalid input. Please try again");
                        }
                        LUIS.InsertIntoCart(Data, context);
                        this.GoBack(context);
                    }
                    else

                    {
                        //string Invalid = LUIS.InvalidInputMessage();


                        // await this.StartAsync(context);
                    }
                }
                catch (Exception e)
                {
                    context.PostAsync("VegException");
                }

                // await this.Vegy(context, choice);
            }



            //string number = String.Empty;
            //foreach (char str in choice)

            //{

            //    if (char.IsDigit(str))

            //        number += str.ToString();



            //}


            //n = float.Parse(number);

            //await context.PostAsync($"You've selected {await result}");

            //await context.PostAsync($"Please enter the quantity in integer only");
            //context.Wait(this.TotalCost);
        }