root / GES_PAC / App.xaml.cs @ 6f451cc1
Historique | Voir | Annoter | Télécharger (1,92 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 | |
14 | //var dbPath = Path.Combine(FileSystem.AppDataDirectory, "GES_PAC.db3"); |
||
15 | //if (File.Exists(dbPath)) |
||
16 | // File.Delete(dbPath); |
||
17 | |||
18 | |||
19 | Db = new AppDbContext(); |
||
20 | Db.Database.EnsureCreated(); |
||
21 | |||
22 | _ = InitSmartEnumsAsync(); |
||
23 | //_ = InitDb(); |
||
24 | 65ad7e66 | Lucas Bihannic | } |
25 | |||
26 | protected override Window CreateWindow(IActivationState? activationState) |
||
27 | { |
||
28 | return new Window(new AppShell()); |
||
29 | } |
||
30 | 6f451cc1 | lbihannic | |
31 | public static async Task InitSmartEnumsAsync() |
||
32 | { |
||
33 | foreach (var phase in PhaseCalibration.All) |
||
34 | { |
||
35 | if (!await Db.PhaseCalibration.AnyAsync(p => p.Value == phase.Value)) |
||
36 | Db.PhaseCalibration.Add(phase); |
||
37 | } |
||
38 | |||
39 | foreach (var type in TypeCalibration.All) |
||
40 | { |
||
41 | if (!await Db.TypeCalibration.AnyAsync(t => t.Value == type.Value)) |
||
42 | Db.TypeCalibration.Add(type); |
||
43 | } |
||
44 | |||
45 | foreach (var comportement in TypeComportement.All) |
||
46 | { |
||
47 | if (!await Db.TypeComportement.AnyAsync(c => c.Value == comportement.Value)) |
||
48 | Db.TypeComportement.Add(comportement); |
||
49 | } |
||
50 | |||
51 | await Db.SaveChangesAsync(); |
||
52 | } |
||
53 | |||
54 | |||
55 | |||
56 | private async Task InitDb() |
||
57 | { |
||
58 | //ONLY FOR TESTS |
||
59 | var place = new Lieu("Elevage Langlade", "INRAE", "Mouton"); |
||
60 | var person = new Personne("Bond", "James", "jamesbond@inrae.fr"); |
||
61 | await Db.Personne.AddAsync(person); |
||
62 | await Db.Lieu.AddAsync(place); |
||
63 | await Db.SaveChangesAsync(); |
||
64 | //ONLY FOR TESTS |
||
65 | } |
||
66 | 65ad7e66 | Lucas Bihannic | } |
67 | } |