HomeHomeDiscussionsDiscussionsGeneralGeneralPass result of a Adaptive card combo box to another methodPass result of a Adaptive card combo box to another method
Previous
 
Next
New Post
8/3/2017 3:27 AM
 

I am using Adaptive card combo box to show some categories of products. Once the user clicks on the category that category should pass to another method and display all the products of that category in another adaptive card Combo Box and let user select a product.

Here is the code to get all category to combo box.

public async Task GetCategoryAdaptiveCard(IDialogContext context)
    {
        var replyToConversation = context.MakeMessage();
        replyToConversation.Attachments = new List<Attachment>();

        HttpResponseMessage response = new HttpResponseMessage();
        string query = string.Format(APIChatBot + "/AllCategory");

        using (var client = ClientHelper.GetClient())
        {
            response = await client.GetAsync(query);
        }
        var categoryList = await response.Content.ReadAsAsync<IEnumerable<CategoryDTO>>();
        AdaptiveCard adaptiveCard = new AdaptiveCard();
        adaptiveCard.Speak = "Please Select A Category from the list";

        adaptiveCard.Body.Add(new TextBlock()
        {
            Text = "Please Select A Category from the list",
            Size = TextSize.Normal,
            Weight = TextWeight.Normal
        });

        adaptiveCard.Body.Add(new TextBlock()
        {
            Text = "Category List",
            Size = TextSize.Normal,
            Weight = TextWeight.Normal
        });

        List<AdaptiveCards.Choice> list = new List<AdaptiveCards.Choice>();

        foreach (var item in categoryList)
        {
            AdaptiveCards.Choice choice = new AdaptiveCards.Choice()
            {
                Title = item.CategoryName,
                Value = item.Id.ToString()
            };

            list.Add(choice);
        }
        adaptiveCard.Body.Add(new ChoiceSet()
        {
            Id = "Category",
            Style = ChoiceInputStyle.Compact,
            Choices = list
        });

        Attachment attachment = new Attachment()
        {
            ContentType = AdaptiveCard.ContentType,
            Content = adaptiveCard
        };

        replyToConversation.Attachments.Add(attachment);
        await context.PostAsync(replyToConversation);
    }

Here is the method i used to get the Product for the selected category.

public async Task GetProductForCategory(IDialogContext context, string category)
    {
        var replyToConversation = context.MakeMessage();
        replyToConversation.Attachments = new List<Attachment>();

        HttpResponseMessage response = new HttpResponseMessage();
        string query = string.Format(APIChatBot + "/ProductByCategory/" + category);

        using (var client = ClientHelper.GetClient())
        {
            response = await client.GetAsync(query);
        }

        var productList = await response.Content.ReadAsAsync<IEnumerable<ProductDTO>>();

        if(productList .Count() == 0)
        {
            string message = "Sorry There Are No products For this Category" + category;
           await context.PostAsync(message);
        }
        else
        {
            List<AdaptiveCards.Choice> list = new List<AdaptiveCards.Choice>();

            foreach (var item in productList )
            {
                AdaptiveCards.Choice choice = new AdaptiveCards.Choice()
                {
                    Title = item.ProductName,
                    Value = item.Id.ToString()
                };

                list.Add(choice);
            }

            AdaptiveCard adaptiveCard = new AdaptiveCard();
            adaptiveCard.Body.Add(new TextBlock()
            {
                Text = "List of Products for the Category " + category,
                Size = TextSize.Normal,
                Weight = TextWeight.Normal
            });

            adaptiveCard.Body.Add(new TextBlock()
            {
                Text = "Please Select A Product From The List",
                Size = TextSize.Normal,
                Weight = TextWeight.Normal
            });

            adaptiveCard.Body.Add(new ChoiceSet()
            {
                Id = "ProductForCategory",
                Style = ChoiceInputStyle.Compact,
                Choices = list
            });

            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content = adaptiveCard
            };

            replyToConversation.Attachments.Add(attachment);
            await context.PostAsync(replyToConversation);
        }
    }

How can i pass the category selected by the user to the method that selects the product based on category?

 
New Post
8/3/2017 5:16 AM
 

I think you received an answer here:

https://stackoverflow.com/questions/4...-another-method

 
New Post
8/3/2017 6:07 AM
 

Yes but for me the answer is not clear, can you please tell me is there another way of doing it. I would really appreciate d help. Thanking in advance

 
New Post
8/3/2017 6:13 AM
 

Sorry but I have no examples.

 
Previous
 
Next
HomeHomeDiscussionsDiscussionsGeneralGeneralPass result of a Adaptive card combo box to another methodPass result of a Adaptive card combo box to another method