Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(context));
  2. if (!roleManager.RoleExists("Admin"))
  3. roleManager.Create(new IdentityRole("Admin"));
  4.  
  5. if (!roleManager.RoleExists("Guest"))
  6. roleManager.Create(new IdentityRole("Guest"));
  7.  
  8. if (!roleManager.RoleExists("Librarian"))
  9. roleManager.Create(new IdentityRole("Librarian"));
  10.  
  11. var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
  12. string[] emails = { "a@a.a", "g@g.g", "l@l.l" };
  13. if (userManager.FindByEmail("a@a.a") == null)
  14. {
  15. var user = new ApplicationUser
  16. {
  17. Email = "a@a.a",
  18. UserName = "a@a.a",
  19. };
  20.  
  21. var result = userManager.Create(user, "P@$$w0rd");
  22. if (result.Succeeded)
  23. userManager.AddToRole(userManager.FindByEmail(user.Email).Id, "Admin");
  24.  
  25. }
  26.  
  27. if (userManager.FindByEmail("g@g.g") == null)
  28. {
  29. var user = new ApplicationUser
  30. {
  31. Email = "g@g.g",
  32. UserName = "g@g.g",
  33. };
  34.  
  35. var result = userManager.Create(user, "P@$$w0rd");
  36. if (result.Succeeded)
  37. userManager.AddToRole(userManager.FindByEmail(user.Email).Id, "Guest");
  38. }
  39.  
  40. if (userManager.FindByEmail("l@l.l") == null)
  41. {
  42. var user = new ApplicationUser
  43. {
  44. Email = "l@l.l",
  45. UserName = "l@l.l",
  46. };
  47.  
  48. var result = userManager.Create(user, "P@$$w0rd");
  49. if (result.Succeeded)
  50. userManager.AddToRole(userManager.FindByEmail(user.Email).Id, "Librarian");
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement