Add new class to have cleaner code

This commit is contained in:
Karol Górzyński 2020-12-03 17:50:11 +01:00
parent 13e0e77b52
commit 50a11e0434
2 changed files with 40 additions and 20 deletions

View File

@ -24,26 +24,7 @@ namespace SessionCompanion.Database
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {
base.OnModelCreating(builder); base.OnModelCreating(builder);
builder.Entity<User>().HasData( builder.Entity<User>().HasData(SeedData.SeedUsers());
new
{
Id = 1,
Nickname = "Morwiec",
Password = "123"
},
new
{
Id = 2,
Nickname = "Cichoklepiec",
Password = "123"
},
new
{
Id = 3,
Nickname = "Ruletka",
Password = "123"
}
);
} }
} }
} }

View File

@ -0,0 +1,39 @@
using Microsoft.EntityFrameworkCore;
using SessionCompanion.Database.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SessionCompanion.Database
{
public class SeedData
{
static public List<User> SeedUsers()
{
List<User> users = new List<User>
{
new User
{
Id = 1,
Nickname = "Morwiec",
Password = "123"
},
new User
{
Id = 2,
Nickname = "Cichoklepiec",
Password = "123"
},
new User
{
Id = 3,
Nickname = "Ruletka",
Password = "123"
}
};
return users;
}
}
}