Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BuyEDalerModel.cs
2using System.Threading.Tasks;
3using System.Windows.Input;
4
6{
10 public class BuyEDalerModel : Model
11 {
12 private readonly ServiceProviderModel[] providers;
13 private readonly Property<ServiceProviderModel> selectedServiceProvider;
14 private readonly Property<decimal> amount;
15 private readonly Property<string> currency;
16 private readonly BuyEDalerDialog dialog;
17 private readonly Command buy;
18 private readonly Command cancel;
19
20 public BuyEDalerModel(BuyEDalerDialog Dialog, Waher.Networking.XMPP.Contracts.IServiceProvider[] Providers, string DefaultCurrency)
21 {
22 this.selectedServiceProvider = new Property<ServiceProviderModel>(nameof(this.SelectedServiceProvider), null, this);
23 this.amount = new Property<decimal>(nameof(this.Amount), 0M, this);
24 this.currency = new Property<string>(nameof(this.Currency), DefaultCurrency, this);
25
26 int i, c = Providers.Length;
27 this.providers = new ServiceProviderModel[c];
28
29 for (i = 0; i < c; i++)
30 this.providers[i] = new ServiceProviderModel(Providers[i]);
31
32 this.dialog = Dialog;
33 this.dialog.DataContext = this;
34
35 this.buy = new Command(this.CanExecuteBuy, this.ExecuteBuy);
36 this.cancel = new Command(this.ExecuteCancel);
37 }
38
43 {
44 get => this.selectedServiceProvider.Value;
45 set
46 {
47 this.selectedServiceProvider.Value = value;
48 this.buy.RaiseCanExecuteChanged();
49 }
50 }
51
55 public ServiceProviderModel[] ServiceProviders => this.providers;
56
60 public decimal Amount
61 {
62 get => this.amount.Value;
63 set
64 {
65 this.amount.Value = value;
66 this.buy.RaiseCanExecuteChanged();
67 }
68 }
69
73 public string Currency
74 {
75 get => this.currency.Value;
76 set
77 {
78 this.currency.Value = value;
79 this.buy.RaiseCanExecuteChanged();
80 }
81 }
82
86 public ICommand Buy => this.buy;
87
91 public ICommand Cancel => this.cancel;
92
93 private bool CanExecuteBuy()
94 {
95 return
96 !(this.SelectedServiceProvider is null) &&
97 this.Amount > 0 &&
98 this.Currency.Length == 3 &&
99 this.Currency.ToUpper() == this.Currency;
100 }
101
102 private Task ExecuteBuy()
103 {
104 this.dialog.DialogResult = true;
105 return Task.CompletedTask;
106 }
107
108 private Task ExecuteCancel()
109 {
110 this.dialog.DialogResult = false;
111 return Task.CompletedTask;
112 }
113 }
114}
Interface for information about a service provider.
Definition: App.xaml.cs:4