Advertisement
Guest User

Untitled

a guest
May 10th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. public class SeedDatabase
  2. {
  3.  
  4. public static async Task Initialize(SpinningDBContext context, UserManager<SpinningUser> userManager, RoleManager<IdentityRole> roleManager)
  5. {
  6.  
  7. context.Database.EnsureCreated();
  8.  
  9. const string adminRole = "Admin";
  10. const string userRole = "User";
  11.  
  12.  
  13. const string userPassword = "Docent@1";
  14. const string userName = "Docent@MCT";
  15.  
  16. if (await roleManager.FindByNameAsync(adminRole) == null)
  17. {
  18. await roleManager.CreateAsync(new IdentityRole(adminRole));
  19. }
  20.  
  21. if (await roleManager.FindByNameAsync(userRole) == null)
  22. {
  23. await roleManager.CreateAsync(new IdentityRole(userRole));
  24. }
  25.  
  26.  
  27. if (await userManager.FindByNameAsync(userName) == null)
  28. {
  29. var user = new SpinningUser
  30. {
  31. UserName = userName,
  32. Email = userName
  33. };
  34.  
  35. var result = await userManager.CreateAsync(user);
  36. if (result.Succeeded)
  37. {
  38. await userManager.AddPasswordAsync(user, userPassword);
  39. await userManager.AddToRoleAsync(user, adminRole);
  40. }
  41. }
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement