Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TransferEDalerModel.cs
2using System.Threading.Tasks;
3using System.Windows.Input;
4
6{
11 {
12 private readonly Property<string> recipient;
13 private readonly Property<decimal> amount;
14 private readonly Property<decimal> amountExtra;
15 private readonly Property<string> currency;
16 private readonly Property<int> validNrDays;
17 private readonly Property<string> message;
18 private readonly TransferEDalerDialog dialog;
19 private readonly Command transfer;
20 private readonly Command cancel;
21
22 public TransferEDalerModel(TransferEDalerDialog Dialog, string DefaultCurrency)
23 {
24 this.recipient = new Property<string>(nameof(this.Recipient), string.Empty, this);
25 this.amount = new Property<decimal>(nameof(this.Amount), 0M, this);
26 this.amountExtra = new Property<decimal>(nameof(this.AmountExtra), 0M, this);
27 this.currency = new Property<string>(nameof(this.Currency), DefaultCurrency, this);
28 this.validNrDays = new Property<int>(nameof(this.ValidNrDays), 3, this);
29 this.message = new Property<string>(nameof(this.Message), string.Empty, this);
30
31 this.dialog = Dialog;
32 this.dialog.DataContext = this;
33
34 this.transfer = new Command(this.CanExecuteTransfer, this.ExecuteTransfer);
35 this.cancel = new Command(this.ExecuteCancel);
36 }
37
41 public string Recipient
42 {
43 get => this.recipient.Value;
44 set
45 {
46 this.recipient.Value = value;
47 this.transfer.RaiseCanExecuteChanged();
48 }
49 }
50
54 public decimal Amount
55 {
56 get => this.amount.Value;
57 set
58 {
59 this.amount.Value = value;
60 this.transfer.RaiseCanExecuteChanged();
61 }
62 }
63
67 public decimal AmountExtra
68 {
69 get => this.amountExtra.Value;
70 set
71 {
72 this.amountExtra.Value = value;
73 this.transfer.RaiseCanExecuteChanged();
74 }
75 }
76
80 public string Currency
81 {
82 get => this.currency.Value;
83 set
84 {
85 this.currency.Value = value;
86 this.transfer.RaiseCanExecuteChanged();
87 }
88 }
89
93 public int ValidNrDays
94 {
95 get => this.validNrDays.Value;
96 set
97 {
98 this.validNrDays.Value = value;
99 this.transfer.RaiseCanExecuteChanged();
100 }
101 }
102
106 public string Message
107 {
108 get => this.message.Value;
109 set
110 {
111 this.message.Value = value;
112 this.transfer.RaiseCanExecuteChanged();
113 }
114 }
115
119 public ICommand Transfer => this.transfer;
120
124 public ICommand Cancel => this.cancel;
125
126 private bool CanExecuteTransfer()
127 {
128 return
129 !string.IsNullOrEmpty(this.Recipient) &&
130 this.Amount > 0 &&
131 this.AmountExtra >= 0 &&
132 this.ValidNrDays > 0 &&
133 this.Currency.Length == 3 &&
134 this.Currency == this.Currency.ToUpper();
135 }
136
137 private Task ExecuteTransfer()
138 {
139 this.dialog.DialogResult = true;
140 return Task.CompletedTask;
141 }
142
143 private Task ExecuteCancel()
144 {
145 this.dialog.DialogResult = false;
146 return Task.CompletedTask;
147 }
148 }
149}