forked from VladislavAntonyuk/MauiSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
71 lines (65 loc) · 1.62 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace KanbanBoard;
using KanbanBoard.Models;
using Microsoft.EntityFrameworkCore;
using Application = Microsoft.Maui.Controls.Application;
public partial class App : Application
{
private readonly IServiceProvider serviceProvider;
public App(IServiceProvider serviceProvider)
{
InitializeComponent();
this.serviceProvider = serviceProvider;
AddTestData().Wait();
MainPage = serviceProvider.GetRequiredService<MainPage>();
}
private async Task AddTestData()
{
using var scope = serviceProvider.CreateScope();
await using var appContext = scope.ServiceProvider.GetRequiredService<KanbanBoardDbContext>();
await appContext.Database.EnsureCreatedAsync();
var items = await appContext.Columns.Include(x => x.Cards).ToArrayAsync();
if (items.Length == 0)
{
var todoColumn = new Column
{
Name = "ToDo",
Order = 0
};
var inProgressColumn = new Column
{
Name = "In Progress",
Order = 1,
Wip = 3
};
await appContext.AddAsync(todoColumn);
await appContext.AddAsync(inProgressColumn);
await appContext.AddAsync(new Column
{
Name = "Done",
Order = 2
});
await appContext.AddAsync(new Card
{
Name = "Card 1",
Description = "Description for card 1",
Order = 0,
Column = todoColumn
});
await appContext.AddAsync(new Card
{
Name = "Card 2",
Description = "Description for card 2",
Order = 1,
Column = todoColumn
});
await appContext.AddAsync(new Card
{
Name = "Card 3",
Description = "Description for card 3",
Order = 0,
Column = inProgressColumn
});
await appContext.SaveChangesAsync();
}
}
}