Skip to content

Instantly share code, notes, and snippets.

@AbubakarSiddiq
Last active November 28, 2020 21:45
Show Gist options
  • Save AbubakarSiddiq/95e94b1670234bb6a73fc2255b2bd791 to your computer and use it in GitHub Desktop.
Save AbubakarSiddiq/95e94b1670234bb6a73fc2255b2bd791 to your computer and use it in GitHub Desktop.
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace BookStore.Data
{
public class SeedDB
{
public static void Initialize(IServiceProvider serviceProvider)
{
var context = serviceProvider.GetRequiredService<BookStoreDbContext>();
var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
context.Database.EnsureCreated();
if (!context.Users.Any())
{
ApplicationUser user = new ApplicationUser()
{
Email = "[email protected]",
UserName = "test",
SecurityStamp = Guid.NewGuid().ToString()
};
userManager.CreateAsync(user, "Test@123");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment