Created
July 12, 2016 03:22
-
-
Save beachside-project/6bd80ce4a8d30aea4afa52fd6a0f7f94 to your computer and use it in GitHub Desktop.
SandwichOrder_BuildForm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IForm<SandwichOrder> BuildForm() | |
{ | |
return new FormBuilder<SandwichOrder>() | |
.Message("サンドイッチボットへようこそ♪") | |
.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 = Enum.GetValues(typeof(ToppingOptions)).Cast<ToppingOptions>() | |
.Where(t => t != ToppingOptions.Everything && !values.Contains(t)).ToList(); | |
} | |
return result; | |
}) | |
.Message("{Toppings}を選択しました。") | |
.Build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment