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