Add sample workflow with IfElse activity

This commit is contained in:
Sipke Schoorstra 2020-12-24 21:39:27 +01:00
parent 599c6a5cd6
commit a1c1ee9ce0
2 changed files with 25 additions and 0 deletions

View file

@ -44,6 +44,7 @@ namespace Elsa.Server.Host
.AddWorkflow<HelloWorldV2>()
.AddWorkflow<GoodbyeWorld>()
.AddWorkflow<NamingWorkflow>()
.AddWorkflow<ConditionWorkflow>()
;
}

View file

@ -0,0 +1,24 @@
using Elsa.Activities.Console;
using Elsa.Activities.ControlFlow;
using Elsa.Activities.Primitives;
using Elsa.Builders;
namespace Elsa.Server.Host.Workflows
{
public class ConditionWorkflow : IWorkflow
{
public void Build(IWorkflowBuilder workflow)
{
workflow
.WithDisplayName("Conditions")
.WriteLine("What is your age?")
.ReadLine()
.SetVariable("Age", context => int.Parse(context.GetInput<string>()))
.IfElse(context => context.GetVariable<int>("Age") < 18, ifElse =>
{
ifElse.When(OutcomeNames.True).WriteLine("You are not allowed to drink beer.");
ifElse.When(OutcomeNames.False).WriteLine("Enjoy your beer!");
});
}
}
}