root / GES_PAC / ViewModel / JourneeViewModel.cs @ 3fef487c
Historique | Voir | Annoter | Télécharger (2,259 ko)
1 | 65ad7e66 | Lucas Bihannic | using GES_PAC.Model; |
---|---|---|---|
2 | 6f451cc1 | lbihannic | using Microsoft.EntityFrameworkCore; |
3 | 65ad7e66 | Lucas Bihannic | using System.Collections.ObjectModel; |
4 | |||
5 | namespace GES_PAC.ViewModel |
||
6 | { |
||
7 | public class JourneeViewModel |
||
8 | { |
||
9 | 18f910c6 | Lucas Bihannic | #region Attributs |
10 | 65ad7e66 | Lucas Bihannic | private static JourneeViewModel _instance; |
11 | 18f910c6 | Lucas Bihannic | #endregion |
12 | |||
13 | #region Propriétés |
||
14 | public ObservableCollection<Journee> Journees { get; set; } = new(); |
||
15 | 65ad7e66 | Lucas Bihannic | public static JourneeViewModel Instance => _instance ??= new JourneeViewModel(); |
16 | 18f910c6 | Lucas Bihannic | #endregion |
17 | 65ad7e66 | Lucas Bihannic | |
18 | 5d673ce0 | Lucas Bihannic | #region Constructeurs |
19 | 6f451cc1 | lbihannic | private JourneeViewModel() { |
20 | _ = InitAsync(); |
||
21 | } |
||
22 | 18f910c6 | Lucas Bihannic | #endregion |
23 | 5d673ce0 | Lucas Bihannic | |
24 | #region Méthodes |
||
25 | 6f451cc1 | lbihannic | public async Task InitAsync() |
26 | 5d673ce0 | Lucas Bihannic | { |
27 | 6f451cc1 | lbihannic | var journees = await App.Db.Journee |
28 | 3fef487c | lbihannic | .Include(j => j.Responsable) |
29 | .Include(j => j.Lieu) |
||
30 | 6f451cc1 | lbihannic | .Include(j => j.Calibrations) |
31 | .ThenInclude(c => c.Mesures) |
||
32 | .ThenInclude(m => m.Type) |
||
33 | .Include(j => j.Calibrations) |
||
34 | .ThenInclude(c => c.Phase) |
||
35 | .Include(j => j.Series) |
||
36 | .ThenInclude(s => s.SeriesAnimales) |
||
37 | .ThenInclude(sa => sa.Mesures) |
||
38 | .Include(j => j.Series) |
||
39 | .ThenInclude(s => s.SeriesAnimales) |
||
40 | .ThenInclude(sa => sa.Comportements) |
||
41 | .ToListAsync(); |
||
42 | |||
43 | foreach (var j in journees) |
||
44 | { |
||
45 | foreach (var c in j.Calibrations) |
||
46 | { |
||
47 | c.Phase = PhaseCalibration.All.FirstOrDefault(p => p.Value == c.Phase?.Value); |
||
48 | foreach (var m in c.Mesures) |
||
49 | { |
||
50 | m.Type = TypeCalibration.All.FirstOrDefault(t => t.Value == m.Type?.Value); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | Journees.Add(j); |
||
55 | } |
||
56 | 5d673ce0 | Lucas Bihannic | } |
57 | 6f451cc1 | lbihannic | public Journee? GetCurrentDay() |
58 | 09d4a0de | lbihannic | { |
59 | 6f451cc1 | lbihannic | DateTime today = DateTime.Today; |
60 | var lastDay = Journees.LastOrDefault(j => j.Date.Date == today); |
||
61 | if (lastDay == null || lastDay.IsComplete()) |
||
62 | return null; |
||
63 | return lastDay; |
||
64 | 1019554c | lbihannic | } |
65 | 42456640 | lbihannic | public Serie? GetCurrentSet() |
66 | 1019554c | lbihannic | { |
67 | 42456640 | lbihannic | return GetCurrentDay()?.GetCurrentSet(); |
68 | 09d4a0de | lbihannic | } |
69 | 5d673ce0 | Lucas Bihannic | #endregion |
70 | 65ad7e66 | Lucas Bihannic | } |
71 | } |