root / GES_PAC / ViewModel / JourneeViewModel.cs @ 3fef487c
Historique | Voir | Annoter | Télécharger (2,259 ko)
1 |
using GES_PAC.Model; |
---|---|
2 |
using Microsoft.EntityFrameworkCore; |
3 |
using System.Collections.ObjectModel; |
4 |
|
5 |
namespace GES_PAC.ViewModel |
6 |
{ |
7 |
public class JourneeViewModel |
8 |
{ |
9 |
#region Attributs |
10 |
private static JourneeViewModel _instance; |
11 |
#endregion |
12 |
|
13 |
#region Propriétés |
14 |
public ObservableCollection<Journee> Journees { get; set; } = new(); |
15 |
public static JourneeViewModel Instance => _instance ??= new JourneeViewModel(); |
16 |
#endregion |
17 |
|
18 |
#region Constructeurs |
19 |
private JourneeViewModel() { |
20 |
_ = InitAsync(); |
21 |
} |
22 |
#endregion |
23 |
|
24 |
#region Méthodes |
25 |
public async Task InitAsync() |
26 |
{ |
27 |
var journees = await App.Db.Journee |
28 |
.Include(j => j.Responsable) |
29 |
.Include(j => j.Lieu) |
30 |
.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 |
} |
57 |
public Journee? GetCurrentDay() |
58 |
{ |
59 |
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 |
} |
65 |
public Serie? GetCurrentSet() |
66 |
{ |
67 |
return GetCurrentDay()?.GetCurrentSet(); |
68 |
} |
69 |
#endregion |
70 |
} |
71 |
} |