Statistiques
| Branche: | Révision:

root / GES_PAC / App.xaml.cs @ 3fef487c

Historique | Voir | Annoter | Télécharger (1,339 ko)

1
using GES_PAC.Model;
2
using GES_PAC.ViewModel;
3
using Microsoft.EntityFrameworkCore;
4

    
5
namespace GES_PAC
6
{
7
    public partial class App : Application
8
    {
9
        public static AppDbContext Db { get; private set; }
10
        public App()
11
        {
12
            InitializeComponent();
13
            Db = new AppDbContext();
14
            Db.Database.EnsureCreated();
15

    
16
            _ = InitSmartEnumsAsync();
17
        }
18

    
19
        protected override Window CreateWindow(IActivationState? activationState)
20
        {
21
            return new Window(new AppShell());
22
        }
23

    
24
        public static async Task InitSmartEnumsAsync()
25
        {
26
            foreach (var phase in PhaseCalibration.All)
27
            {
28
                if (!await Db.PhaseCalibration.AnyAsync(p => p.Value == phase.Value))
29
                    Db.PhaseCalibration.Add(phase);
30
            }
31

    
32
            foreach (var type in TypeCalibration.All)
33
            {
34
                if (!await Db.TypeCalibration.AnyAsync(t => t.Value == type.Value))
35
                    Db.TypeCalibration.Add(type);
36
            }
37
       
38
            foreach (var comportement in TypeComportement.All)
39
            {
40
                if (!await Db.TypeComportement.AnyAsync(c => c.Value == comportement.Value))
41
                    Db.TypeComportement.Add(comportement);
42
            }
43
            await Db.SaveChangesAsync();
44
        }
45
    }
46
}