root / GES_PAC / App.xaml.cs @ 3fef487c
Historique | Voir | Annoter | Télécharger (1,339 ko)
1 | 6f451cc1 | lbihannic | using GES_PAC.Model; |
---|---|---|---|
2 | using GES_PAC.ViewModel; |
||
3 | using Microsoft.EntityFrameworkCore; |
||
4 | |||
5 | 65ad7e66 | Lucas Bihannic | namespace GES_PAC |
6 | { |
||
7 | public partial class App : Application |
||
8 | { |
||
9 | 6f451cc1 | lbihannic | public static AppDbContext Db { get; private set; } |
10 | 65ad7e66 | Lucas Bihannic | public App() |
11 | { |
||
12 | InitializeComponent(); |
||
13 | 6f451cc1 | lbihannic | Db = new AppDbContext(); |
14 | Db.Database.EnsureCreated(); |
||
15 | |||
16 | _ = InitSmartEnumsAsync(); |
||
17 | 65ad7e66 | Lucas Bihannic | } |
18 | |||
19 | protected override Window CreateWindow(IActivationState? activationState) |
||
20 | { |
||
21 | return new Window(new AppShell()); |
||
22 | } |
||
23 | 6f451cc1 | lbihannic | |
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 | 65ad7e66 | Lucas Bihannic | } |
46 | } |