forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Order.cs
103 lines (81 loc) · 3.45 KB
/
Order.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
namespace ContosoFlowers.Models
{
using System;
using BotAssets;
using Microsoft.Bot.Builder.FormFlow;
using Microsoft.Bot.Builder.FormFlow.Advanced;
using Services.Models;
[Serializable]
public class Order
{
public enum UseSaveInfoResponse
{
Yes,
Edit
}
public string OrderID { get; set; }
[Prompt]
public string RecipientFirstName { get; set; }
[Prompt(FieldCase = CaseNormalization.None)]
public string RecipientLastName { get; set; }
[Prompt]
[Pattern(RegexConstants.Phone)]
public string RecipientPhoneNumber { get; set; }
[Prompt]
[Pattern(@"^.{1,200}$")]
public string Note { get; set; }
[Prompt]
[Pattern(RegexConstants.Email)]
public string SenderEmail { get; set; }
[Prompt]
[Pattern(RegexConstants.Phone)]
public string SenderPhoneNumber { get; set; }
public string SenderFirstName { get; set; }
public string SenderLastName { get; set; }
public bool AskToUseSavedSenderInfo { get; set; }
[Prompt]
public UseSaveInfoResponse? UseSavedSenderInfo { get; set; }
[Prompt]
public bool SaveSenderInfo { get; set; }
public string DeliveryAddress { get; set; }
public string FlowerCategoryName { get; set; }
public Bouquet Bouquet { get; set; }
public DateTime DeliveryDate { get; set; }
public string BillingAddress { get; set; }
public bool Payed { get; set; }
public PaymentDetails PaymentDetails { get; set; }
public static IForm<Order> BuildOrderForm()
{
return new FormBuilder<Order>()
.Field(nameof(RecipientFirstName))
.Field(nameof(RecipientLastName))
.Field(nameof(RecipientPhoneNumber))
.Field(nameof(Note))
.Field(new FieldReflector<Order>(nameof(UseSavedSenderInfo))
.SetActive(state => state.AskToUseSavedSenderInfo)
.SetNext((value, state) =>
{
var selection = (UseSaveInfoResponse)value;
if (selection == UseSaveInfoResponse.Edit)
{
state.SenderEmail = null;
state.SenderPhoneNumber = null;
return new NextStep(new[] { nameof(SenderEmail) });
}
else
{
return new NextStep();
}
}))
.Field(new FieldReflector<Order>(nameof(SenderEmail))
.SetActive(state => !state.UseSavedSenderInfo.HasValue || state.UseSavedSenderInfo.Value == UseSaveInfoResponse.Edit)
.SetNext(
(value, state) => (state.UseSavedSenderInfo == UseSaveInfoResponse.Edit)
? new NextStep(new[] { nameof(SenderPhoneNumber) })
: new NextStep()))
.Field(nameof(SenderPhoneNumber), state => !state.UseSavedSenderInfo.HasValue || state.UseSavedSenderInfo.Value == UseSaveInfoResponse.Edit)
.Field(nameof(SaveSenderInfo), state => !state.UseSavedSenderInfo.HasValue || state.UseSavedSenderInfo.Value == UseSaveInfoResponse.Edit)
.Build();
}
}
}