inraetemplate / INRAETemplate / ViewModel / VivantViewModel.cs @ 7b67ff55
Historique | Voir | Annoter | Télécharger (3,268 ko)
1 |
using INRAETemplate.DAO; |
---|---|
2 |
using INRAETemplate.Model; |
3 |
using INRAETemplate.Services; |
4 |
using INRAETemplate.View; |
5 |
using INRAETemplate.ViewModel.Base; |
6 |
using System; |
7 |
using System.Collections.Generic; |
8 |
using System.Collections.ObjectModel; |
9 |
using System.Linq; |
10 |
using System.Text; |
11 |
using System.Threading.Tasks; |
12 |
using System.Windows.Input; |
13 |
|
14 |
namespace INRAETemplate.ViewModel |
15 |
{ |
16 |
public class VivantViewModel : BaseViewModel |
17 |
{ |
18 |
#region Services |
19 |
|
20 |
private readonly ConnexionService connService; |
21 |
|
22 |
#endregion |
23 |
|
24 |
#region Attributs |
25 |
private int vivantId; |
26 |
private string vivantNom; |
27 |
//Pour le Picker : attributs vivants et vivantSelectionne |
28 |
private ObservableCollection<Vivant> vivants; |
29 |
private Vivant vivantSelectionne; |
30 |
#endregion |
31 |
|
32 |
#region Commandes |
33 |
public ICommand EditionCommand { get; private set; } |
34 |
#endregion |
35 |
|
36 |
#region Propriétés |
37 |
public int VivantId |
38 |
{ |
39 |
get { return vivantId; } |
40 |
set |
41 |
{ |
42 |
if (vivantId != value) |
43 |
{ |
44 |
vivantId = value; |
45 |
OnPropertyChanged(nameof(VivantId)); |
46 |
} |
47 |
} |
48 |
} |
49 |
|
50 |
public string VivantNom |
51 |
{ |
52 |
get { return vivantNom; } |
53 |
set |
54 |
{ |
55 |
if (vivantNom != value) |
56 |
{ |
57 |
vivantNom = value; |
58 |
OnPropertyChanged(nameof(VivantNom)); |
59 |
} |
60 |
} |
61 |
} |
62 |
//Pour le Picker : propriétés Vivants et VivantSelectionne |
63 |
public ObservableCollection<Vivant> Vivants |
64 |
{ |
65 |
get { return vivants; } |
66 |
set |
67 |
{ |
68 |
if (vivants != value) |
69 |
{ |
70 |
vivants = value; |
71 |
OnPropertyChanged(nameof(Vivants)); |
72 |
} |
73 |
} |
74 |
} |
75 |
|
76 |
public Vivant VivantSelectionne |
77 |
{ |
78 |
get { return vivantSelectionne; } |
79 |
set |
80 |
{ |
81 |
if (vivantSelectionne != value) |
82 |
{ |
83 |
vivantSelectionne = value; |
84 |
OnPropertyChanged(nameof(vivantSelectionne)); |
85 |
VivantId = vivantSelectionne.VivantId; |
86 |
VivantNom = vivantSelectionne.VivantNom; |
87 |
} |
88 |
} |
89 |
} |
90 |
#endregion |
91 |
|
92 |
#region Constructeurs |
93 |
|
94 |
public VivantViewModel(ConnexionService connService) |
95 |
{ |
96 |
this.connService = connService; |
97 |
//Alimentation du Picker à partir de VivantDAO |
98 |
Vivants = new ObservableCollection<Vivant>(VivantDAO.GetVivants()); |
99 |
EditionCommand = new Command(async () => await Edition()); |
100 |
} |
101 |
|
102 |
#endregion |
103 |
|
104 |
#region Méthodes |
105 |
private async Task Edition() |
106 |
{ |
107 |
IsBusy = true; |
108 |
await Task.Delay(1000); |
109 |
IDictionary<string, object> proprietes = new Dictionary<string, object>(); |
110 |
proprietes.Add("IdVivant", VivantId); |
111 |
await Shell.Current.GoToAsync(nameof(VivantEditionView), true, proprietes); |
112 |
IsBusy = false; |
113 |
} |
114 |
#endregion |
115 |
|
116 |
} |
117 |
} |