Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. protected override void Seed(Musikeroo.Models.ApplicationDbContext context)
  2.         {
  3.             var store = new RoleStore<IdentityRole>(context);
  4.             var manager = new RoleManager<IdentityRole>(store);
  5.             if (!context.Roles.Any(r => r.Name == "Client"))
  6.             {
  7.                 manager.Create(new IdentityRole { Name = "Client" });
  8.             }
  9.             if (!context.Roles.Any(r => r.Name == "Admin"))
  10.             {
  11.                 manager.Create(new IdentityRole { Name = "Admin" });
  12.             }
  13.  
  14.             if (!context.Users.Any(u => u.UserName == "ad@m.in"))
  15.             {
  16.                  string password = new PasswordHasher().HashPassword("https://localhost:44309/Account/Login");
  17.                  context.Users.AddOrUpdate(u => u.UserName,
  18.                      new ApplicationUser
  19.                      {
  20.                          UserName = "ad@m.in",
  21.                          PasswordHash = password,
  22.                          Email = "ad@m.in",
  23.                          FirstName = "Admin",
  24.                          LastName = "YOLO",
  25.  
  26.                      }
  27.                  );
  28.                  Roles.AddUserToRole("ad@m.in", "Admin");
  29.             }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement