public async Task SelectedCategoryItem(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            ;
            var response = turnContext.Activity.Text;

            string text = "";
            var    item = RecommenderClient.ProcessItem(response);

            if (item != null)
            {
                state.SelectedItems.Add(item);
                text = $"You have choosen {response}. Type \"OK\" to continue.";
                state.LastProcessedItem = response;
                state.TurnCount         = State.CHOOSE_RECOMMENDED_ITEM;
            }
            else
            {
                text            = $"You have choosen an invalid item. Type \"OK\" to continue and select a correct item.";
                state.TurnCount = State.CHOOSE_CATEGORY_ITEM;
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            await turnContext.SendActivityAsync(text);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="state"></param>
        /// <param name="turnContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task StartConversation(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.From.Properties["userId"] != null)
            {
                state.UserId = turnContext.Activity.From.Properties["userId"].ToString();
            }

            if (turnContext.Activity.From.Properties["cartId"] != null)
            {
                state.CartId = turnContext.Activity.From.Properties["cartId"].ToString();
            }

            if (turnContext.Activity.From.Properties["name"] != null)
            {
                state.Name = turnContext.Activity.From.Properties["name"].ToString();
            }

            state.TurnCount = State.CHOOSE_CATEGORY;

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            state.LastProcessedItem = "";

            string hello = $"Hello, '{state.Name}'. I am your personal shopping assistant and I will guide you during the shopping process." +
                           $"\n" +
                           $"\n Please select what you want to buy:" +
                           $"\n\t\t1) Tobacco" +
                           $"\n\t\t2) Liquor" +
                           $"\n\t\t3) Food" +
                           $"\n\t\t4) Perfumes & Cosmetics";

            await turnContext.SendActivityAsync(hello);
        }
        public async Task ChooseItemCategory(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var response = turnContext.Activity.Text;

            if (response != null && response.Contains("1"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("10");

                string text = $"Following items are top sellers in the category: 10\n";
                int    cnt  = 1;
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{cnt}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }

            //TODO add for other categories
        }
        public async Task CloseCart(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.DataSource     = "mindshopper.database.windows.net";
            builder.UserID         = "mindshopper";
            builder.Password       = "******";
            builder.InitialCatalog = "mindshopper";


            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();
                    foreach (Item i in state.SelectedItems)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("INSERT INTO [dbo].[item_cart] (id,item_id, item_description, price, quantity, category_id, category_description, cart_id) VALUES");
                        sb.Append($"(NEXT VALUE FOR Hibernate_Sequence,'{i.ItemId}', '{i.ItemName}', {i.SalesValue/100}, 1, '{i.CategoryCode}', '{i.Category}', {state.CartId})");
                        String sql = sb.ToString();

                        using (SqlCommand command = new SqlCommand(sql, connection))
                        {
                            command.ExecuteNonQuery();
                        }
                    }

                    StringBuilder sb2 = new StringBuilder();
                    sb2.Append("UPDATE [dbo].[cart] SET STATUS = 'COMPLETED'");
                    sb2.Append($"where id = {state.CartId}");
                    String sql2 = sb2.ToString();

                    using (SqlCommand command = new SqlCommand(sql2, connection))
                    {
                        command.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.ToString());
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);
        }
        public async Task HelloUser1(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            state.TurnCount = State.CHOOSE_CATEGORY;
            state.UserId    = "Dumi";

            // Set the property using the accessor.
            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            // Save the new turn count into the conversation state.
            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            // Echo back to the user whatever they typed.
            var responseMessage = $"Turn {state.TurnCount}: Hello '{state.Name}'";


            await turnContext.SendActivityAsync(responseMessage);
        }
        public async Task SelectedRecommendedItem(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            string text     = "";
            var    response = turnContext.Activity.Text;

            if (response != null)
            {
                if (!response.ToLower().Contains("no"))
                {
                    var item = RecommenderClient.ProcessItem(response);
                    if (item != null)
                    {
                        state.SelectedItems.Add(item);
                        text = $"You have choosen {response}. Type \"OK\" to continue.";
                        state.LastProcessedItem = response;
                        state.TurnCount         = State.CHOOSE_RECOMMENDED_ITEM;
                    }
                    else
                    {
                        text            = $"You have choosen an invalid item. Type \"OK\" to continue and select a correct item.";
                        state.TurnCount = State.CHOOSE_CATEGORY_ITEM;
                    }
                }
                else
                {
                    state.TurnCount = State.CHOOSE_CATEGORY;
                    text            = $"You are being sent back to the category choosing.\n Please select the category of interest:" +
                                      $"\n\t\t1) Tobacco" +
                                      $"\n\t\t2) Liquor" +
                                      $"\n\t\t3) Food" +
                                      $"\n\t\t4) Perfumes & Cosmetics" +
                                      $"\n\t\tType\"none\" to close the cart.";
                }
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            await turnContext.SendActivityAsync(text);
        }
        public async Task ChooseRecommendedItem(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var    response = turnContext.Activity.Text;
            string text     = "";

            if (response != null)
            {
                if (!response.ToLower().Contains("no"))
                {
                    response = response.ToLower().Equals("ok") ? state.LastProcessedItem : response;

                    IList <Item> list = RecommenderClient.ProcessRecommendedItem(response);

                    text = $"Following items are recommended to you based on the current items in your cart:\n";
                    foreach (Item i in list)
                    {
                        text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                    }
                    text += "\n Choose the item, otherwise, type \"none\".";

                    state.TurnCount = State.SELECTED_RECOMMENDED_ITEM;
                }
                else
                {
                    state.TurnCount = State.CHOOSE_CATEGORY;
                }
            }
            else
            {
                state.TurnCount = State.CHOOSE_RECOMMENDED_ITEM;
            }

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);

            await turnContext.SendActivityAsync(text);
        }
        public async Task ChooseCategory(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var response = turnContext.Activity.Text;

            if (response != null && response.Contains("1"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("10");

                string text = $"Following items are top sellers in the category: 10\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.Contains("2"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("20");

                string text = $"Following items are top sellers in the category: 20\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.Contains("3"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("30");

                string text = $"Following items are top sellers in the category: 30\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.Contains("4"))
            {
                IList <Item> list = RecommenderClient.ProcessTopItems("40");

                string text = $"Following items are top sellers in the category: 40\n";
                foreach (Item i in list)
                {
                    text += $"\n\t\t '{i.ItemId}' - " + i.ItemName;
                }
                text += "\n Choose the item";

                state.TurnCount = State.SELECTED_CATEGORY_ITEM;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
            else if (response != null && response.ToLower().Contains("no"))
            {
                string text = $"Thank you for buying. Have a nice day! Type \"OK\" to confirm the completion of the cart.";
                state.TurnCount = State.END;

                await _accessors.MindshopperUserState.SetAsync(turnContext, state);

                await _accessors.ConversationState.SaveChangesAsync(turnContext);

                await turnContext.SendActivityAsync(text);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="state"></param>
        /// <param name="turnContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task StartConversation(MindshopperUserState state, ITurnContext turnContext, CancellationToken cancellationToken)
        {
            /*
             * IConversationUpdateActivity update = turnContext.Activity;
             *
             * if (update.MembersAdded != null && update.MembersAdded.Any())
             * {
             *  foreach (var newMember in update.MembersAdded)
             *  {
             *      if (newMember.Id != turnContext.Activity.Recipient.Id)
             *      {
             *          if (turnContext.Activity.From.Properties["userId"] != null)
             *          {
             *              state.UserId = turnContext.Activity.From.Properties["userId"].ToString();
             *          }
             *
             *          if (turnContext.Activity.From.Properties["cartId"] != null)
             *          {
             *              state.CartId = turnContext.Activity.From.Properties["cartId"].ToString();
             *          }
             *
             *          if (turnContext.Activity.From.Properties["name"] != null)
             *          {
             *              state.Name = turnContext.Activity.From.Properties["name"].ToString();
             *          }
             *
             *          state.TurnCount = State.CHOOSE_CATEGORY;
             *
             *          await _accessors.MindshopperUserState.SetAsync(turnContext, state);
             *          await _accessors.ConversationState.SaveChangesAsync(turnContext);
             *
             *
             *          string hello = $"Hello, '{state.Name}'. I am your personal shopping assistant and I will guide you during the shopping process." +
             *              $"\n" +
             *              $"\n Please select what you want to buy:" +
             *              $"\n\t\t1) Tobacco" +
             *              $"\n\t\t2) Food" +
             *              $"\n\t\t3) Perfumes & Cosmetics" +
             *              $"\n\t\t4) Liquor";
             *
             *          await turnContext.SendActivityAsync(hello);
             *      }
             *  }
             * }*/


            if (turnContext.Activity.From.Properties["userId"] != null)
            {
                state.UserId = turnContext.Activity.From.Properties["userId"].ToString();
            }

            if (turnContext.Activity.From.Properties["cartId"] != null)
            {
                state.CartId = turnContext.Activity.From.Properties["cartId"].ToString();
            }

            if (turnContext.Activity.From.Properties["name"] != null)
            {
                state.Name = turnContext.Activity.From.Properties["name"].ToString();
            }

            state.TurnCount = State.CHOOSE_CATEGORY;

            await _accessors.MindshopperUserState.SetAsync(turnContext, state);

            await _accessors.ConversationState.SaveChangesAsync(turnContext);


            string hello = $"Hello, '{state.Name}'. I am your personal shopping assistant and I will guide you during the shopping process." +
                           $"\n" +
                           $"\n Please select what you want to buy:" +
                           $"\n\t\t1) Tobacco" +
                           $"\n\t\t2) Food" +
                           $"\n\t\t3) Perfumes & Cosmetics" +
                           $"\n\t\t4) Liquor";

            await turnContext.SendActivityAsync(hello);
        }