Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions articles/includes/code/dotnet-formflow-advanced.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// <validationFunction>
.Field(nameof(Toppings),
validate: async (state, value) =>
{
var values = ((List<object>)value).OfType<ToppingOptions>();
var result = new ValidateResult { IsValid = true, Value = values };
if (values != null && values.Contains(ToppingOptions.Everything))
{
result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions))
where topping != ToppingOptions.Everything && !values.Contains(topping)
select topping).ToList();
}
return result;
})
public static IForm<SandwichOrder> BuildForm()
{
...
return new FormBuilder<SandwichOrder>()
.Message("Welcome to the sandwich order bot!")
...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the "..." here and instead add these four lines that precede the Toppings line in the sample app:

.Field(nameof(Sandwich))
.Field(nameof(Length))
.Field(nameof(Bread))
.Field(nameof(Cheese))

.Field(nameof(Toppings),
validate: async (state, value) =>
{
var values = ((List<object>)value).OfType<ToppingOptions>();
var result = new ValidateResult { IsValid = true, Value = values };
if (values != null && values.Contains(ToppingOptions.Everything))
{
result.Value = (from ToppingOptions topping in Enum.GetValues(typeof(ToppingOptions))
where topping != ToppingOptions.Everything && !values.Contains(topping)
select topping).ToList();
}
return result;
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent "})" further so that its indentation matches the opening brace "{" for the validate function.

.Message("For sandwich toppings you have selected {Toppings}.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After the line .Message("For sandwich toppings you have selected {Toppings}."), please add these 3 lines:

        ...
        .Build();
}

Four your reference (re proper indentation), here's what all four of those lines should look like together:

        .Message("For sandwich toppings you have selected {Toppings}.")
        ...
        .Build();
}

.Message("For sandwich toppings you have selected {Toppings}.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, please remove the duplicate line .Message("For sandwich toppings you have selected {Toppings}.") from the end of the snippet.

// </validationFunction>

Expand Down