jesus
jesus

Reputation: 39

Skips questions depending on a choice

I would like to know if it is possible that, depending on the user's choice, all the questions may be skipped and the dialogue terminated.

Example, I have the next code:

public ContentClassification ContentClassification {get;set;}

public StatusOfContent StatusContent {get; set;}

public Accessibility ExternalSharing {get; set;}

Depending on the choice of "ContentClassification", skip the other questions.

Thanks in advance.

Upvotes: 0

Views: 74

Answers (1)

Grace Feng
Grace Feng

Reputation: 16652

Depending on the choice of "ContentClassification", skip the other questions.

You can use FieldReflector to implement your own IField, for example:

public enum ContentClassification
{
    Confidential_Restricted = 1,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};

public enum StatusContent
{
    Status1,
    Status2
}

public enum Accessibility
{
    Accessibility1,
    Accessibility2
}

[Serializable]
public class Classification
{
    public ContentClassification? Choice { get; set; }
    public StatusContent? StatusOfContent { get; set; }
    public Accessibility? Accessibility { get; set; }

    public static bool Confirmation = true;

    public static IForm<Classification> BuildForm()
    {
        return new FormBuilder<Classification>()
            .Message("You want to")
            .Field(new FieldReflector<Classification>(nameof(Choice))
                   .SetNext((value, state) =>
                   {
                       var selection = (ContentClassification)value;
                       if (selection == ContentClassification.help)
                       {
                           Confirmation = false;
                           state.Accessibility = null;
                           state.StatusOfContent = null;
                       }
                       else
                       {
                           Confirmation = true;
                       }
                       return new NextStep();
                   }))
              .Field(new FieldReflector<Classification>(nameof(StatusOfContent))
                   .SetActive(state => Confirmation))
              .Field(new FieldReflector<Classification>(nameof(Accessibility))
                   .SetActive(state => Confirmation))
            .Build();
    }
}

And in the RootDialog:

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        var form = new FormDialog<Classification>(new Classification(), Classification.BuildForm, FormOptions.PromptInStart, null);
        context.Call(form, this.GetResultAsync);

        return Task.CompletedTask;
    }

    private async Task GetResultAsync(IDialogContext context, IAwaitable<Classification> result)
    {
        var state = await result;
        //TODO:
    }
}

Using this code, when user select Help in the first dialog Choice, it will skip the following two questions and you will get the result in GetResultAsync with Choice = Help, StatusOfContent = null, Accessibility = null and so on.

Upvotes: 1

Related Questions