30 lines
867 B
C#
30 lines
867 B
C#
using JSMR.Domain.Entities;
|
|
using JSMR.Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace JSMR.Api.Startup;
|
|
|
|
public static class DevSeeding
|
|
{
|
|
public static async Task SeedDevelopmentAsync(this WebApplication app)
|
|
{
|
|
using var scope = app.Services.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
|
|
|
var username = "brister";
|
|
|
|
if (!await db.Users.AnyAsync(u => u.Username == username))
|
|
{
|
|
db.Users.Add(new User
|
|
{
|
|
Username = username,
|
|
PasswordHash = BCrypt.Net.BCrypt.HashPassword("password"),
|
|
Role = "Admin",
|
|
IsActive = true
|
|
});
|
|
|
|
await db.SaveChangesAsync();
|
|
Console.WriteLine("✅ Seeded development user: brister / password");
|
|
}
|
|
}
|
|
} |