Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AddLanguageModel.cs
3using System.Threading.Tasks;
4using System.Windows.Input;
5
7{
11 public class AddLanguageModel : Model
12 {
13 private readonly Property<string> selectedLanguage;
14 private readonly AddLanguageDialog dialog;
15 private readonly Command add;
16 private readonly Command cancel;
17
19 {
20 this.selectedLanguage = new Property<string>(nameof(this.SelectedLanguage), string.Empty, this);
21
22 this.dialog = Dialog;
23 this.dialog.DataContext = this;
24
25 this.add = new Command(this.CanExecuteAdd, this.ExecuteAdd);
26 this.cancel = new Command(this.ExecuteCancel);
27 }
28
32 public string SelectedLanguage
33 {
34 get => this.selectedLanguage.Value;
35 set
36 {
37 this.selectedLanguage.Value = value;
38 this.add.RaiseCanExecuteChanged();
39 }
40 }
41
45 public static Iso__639_1.Record[] Languages
46 {
47 get => Iso__639_1.Data;
48 }
49
53 public ICommand Add => this.add;
54
58 public ICommand Cancel => this.cancel;
59
60 private bool CanExecuteAdd()
61 {
62 return !string.IsNullOrEmpty(this.SelectedLanguage) && Iso__639_1.CodeToLanguage(this.SelectedLanguage, out _);
63 }
64
65 private Task ExecuteAdd()
66 {
67 this.dialog.DialogResult = true;
68 return Task.CompletedTask;
69 }
70
71 private Task ExecuteCancel()
72 {
73 this.dialog.DialogResult = false;
74 return Task.CompletedTask;
75 }
76 }
77}