Révision 6f451cc1 GES_PAC/App.xaml.cs

Voir les différences:

GES_PAC/App.xaml.cs
1
using GES_PAC.Model;
2
using GES_PAC.ViewModel;
3
using Microsoft.EntityFrameworkCore;
4

  
1 5
namespace GES_PAC
2 6
{
3 7
    public partial class App : Application
4 8
    {
9
        public static AppDbContext Db { get; private set; }
5 10
        public App()
6 11
        {
7 12
            InitializeComponent();
13

  
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();
8 24
        }
9 25

  
10 26
        protected override Window CreateWindow(IActivationState? activationState)
11 27
        {
12 28
            return new Window(new AppShell());
13 29
        }
30

  
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
        }
14 66
    }
15 67
}

Formats disponibles : Unified diff