IW4M-Admin/SharedLibraryCore/Database/ContextSeed.cs

52 lines
1.4 KiB
C#
Raw Normal View History

2018-04-08 02:44:42 -04:00
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Database.Models;
using System;
using System.Linq;
using System.Threading.Tasks;
using static SharedLibraryCore.Database.Models.EFClient;
2018-04-08 02:44:42 -04:00
namespace SharedLibraryCore.Database
{
public class ContextSeed
{
private DatabaseContext context;
public ContextSeed(DatabaseContext ctx)
{
context = ctx;
}
public async Task Seed()
{
context.Database.Migrate();
2018-04-08 02:44:42 -04:00
if (context.AliasLinks.Count() == 0)
{
var link = new EFAliasLink();
2018-04-08 02:44:42 -04:00
context.Clients.Add(new EFClient()
{
ClientId = 1,
Active = false,
Connections = 0,
FirstConnection = DateTime.UtcNow,
LastConnection = DateTime.UtcNow,
Level = Permission.Console,
2018-04-08 02:44:42 -04:00
Masked = true,
NetworkId = 0,
AliasLink = link,
CurrentAlias = new EFAlias()
{
Link = link,
Active = true,
DateAdded = DateTime.UtcNow,
Name = "IW4MAdmin",
},
2018-04-08 02:44:42 -04:00
});
await context.SaveChangesAsync();
}
}
}
}