Statistiques
| Branche: | Révision:

root / GES_PAC / ViewModel / JourneeViewModel.cs @ 6f451cc1

Historique | Voir | Annoter | Télécharger (2,179 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
                .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
            }
55 5d673ce0 Lucas Bihannic
        }
56 6f451cc1 lbihannic
        public Journee? GetCurrentDay()
57 09d4a0de lbihannic
        {
58 6f451cc1 lbihannic
            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;
63 1019554c lbihannic
        }
64 42456640 lbihannic
        public Serie? GetCurrentSet()
65 1019554c lbihannic
        {
66 42456640 lbihannic
            return GetCurrentDay()?.GetCurrentSet();
67 09d4a0de lbihannic
        }
68 5d673ce0 Lucas Bihannic
        #endregion
69 65ad7e66 Lucas Bihannic
    }
70
}