Révision 6f451cc1 GES_PAC/ViewModel/JourneeViewModel.cs
GES_PAC/ViewModel/JourneeViewModel.cs | ||
---|---|---|
1 | 1 |
using GES_PAC.Model; |
2 |
using Microsoft.EntityFrameworkCore; |
|
2 | 3 |
using System.Collections.ObjectModel; |
3 | 4 |
|
4 | 5 |
namespace GES_PAC.ViewModel |
... | ... | |
15 | 16 |
#endregion |
16 | 17 |
|
17 | 18 |
#region Constructeurs |
18 |
private JourneeViewModel() { } |
|
19 |
private JourneeViewModel() { |
|
20 |
_ = InitAsync(); |
|
21 |
} |
|
19 | 22 |
#endregion |
20 | 23 |
|
21 | 24 |
#region Méthodes |
22 |
public Journee GetCurrentDay()
|
|
25 |
public async Task InitAsync()
|
|
23 | 26 |
{ |
24 |
DateTime today = DateTime.Today; |
|
25 |
return Journees.LastOrDefault(j => j.Date.Date == today); |
|
27 |
var journees = await App.Db.Journee |
|
28 |
.Include(j => j.Calibrations) |
|
29 |
.ThenInclude(c => c.Mesures) |
|
30 |
.ThenInclude(m => m.Type) |
|
31 |
.Include(j => j.Calibrations) |
|
32 |
.ThenInclude(c => c.Phase) |
|
33 |
.Include(j => j.Series) |
|
34 |
.ThenInclude(s => s.SeriesAnimales) |
|
35 |
.ThenInclude(sa => sa.Mesures) |
|
36 |
.Include(j => j.Series) |
|
37 |
.ThenInclude(s => s.SeriesAnimales) |
|
38 |
.ThenInclude(sa => sa.Comportements) |
|
39 |
.ToListAsync(); |
|
40 |
|
|
41 |
|
|
42 |
foreach (var j in journees) |
|
43 |
{ |
|
44 |
foreach (var c in j.Calibrations) |
|
45 |
{ |
|
46 |
c.Phase = PhaseCalibration.All.FirstOrDefault(p => p.Value == c.Phase?.Value); |
|
47 |
foreach (var m in c.Mesures) |
|
48 |
{ |
|
49 |
m.Type = TypeCalibration.All.FirstOrDefault(t => t.Value == m.Type?.Value); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
Journees.Add(j); |
|
54 |
} |
|
26 | 55 |
} |
27 |
public PhaseCalibration GetCurrentPhase()
|
|
56 |
public Journee? GetCurrentDay()
|
|
28 | 57 |
{ |
29 |
return GetCurrentDay().GetCurrentPhase(); |
|
58 |
DateTime today = DateTime.Today; |
|
59 |
var lastDay = Journees.LastOrDefault(j => j.Date.Date == today); |
|
60 |
if (lastDay == null || lastDay.IsComplete()) |
|
61 |
return null; |
|
62 |
return lastDay; |
|
30 | 63 |
} |
31 | 64 |
public Serie? GetCurrentSet() |
32 | 65 |
{ |
Formats disponibles : Unified diff