SHARE
TWEET

Untitled

a guest Feb 4th, 2016 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected override void Seed(ApplicationDbContext context)
  2.     {
  3.         var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
  4.         var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
  5.  
  6.         var user = new ApplicationUser
  7.         {
  8.             UserName = "SomeEmail@gmail.com",
  9.             Email = "SomeEmail@gmail.com",
  10.             EmailConfirmed = true
  11.         };
  12.  
  13.         userManager.Create(user, "APASSWORDHERE");
  14.  
  15.         if (roleManager.Roles.Count() == 0)
  16.         {
  17.             roleManager.Create(new IdentityRole { Name = "SuperAdmin" });
  18.             roleManager.Create(new IdentityRole { Name = "Admin" });
  19.             roleManager.Create(new IdentityRole { Name = "CLevel" });
  20.             roleManager.Create(new IdentityRole { Name = "DistrictManager" });
  21.             roleManager.Create(new IdentityRole { Name = "AreaManager" });
  22.             roleManager.Create(new IdentityRole { Name = "OfficeStaff" });
  23.             roleManager.Create(new IdentityRole { Name = "Contractor" });
  24.             roleManager.Create(new IdentityRole { Name = "Client" });
  25.         }
  26.  
  27.         ApplicationUser adminIdentityUser = userManager.FindByName("SomeEmail@gmail.com");
  28.  
  29.         userManager.AddToRoles(adminIdentityUser.Id, new string[] { "SuperAdmin", "Admin" });
  30.     }
  31.    
  32. protected override void Seed(HTNContext context)
  33.     {
  34.         var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
  35.         var userContext = new Users();  //Repository connected to MyContext
  36.  
  37.         ApplicationUser adminIdentityUser = userManager.FindByName("SomeEmail@gmail.com");
  38.  
  39.         User adminUser = new User
  40.         {
  41.             EmailAddress = adminIdentityUser.Email,
  42.             FName = "Admin",
  43.             Id = Guid.Parse(adminIdentityUser.Id),
  44.             JoinDate = DateTime.Now.AddYears(-3),
  45.             LName = "User"
  46.         };
  47.  
  48.         userContext.Create(adminUser);
  49.     }
  50.    
  51. protected override void Seed(ApplicationDbContext context)
  52.     {
  53.         var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
  54.         var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));
  55.         var userContext = new Users();  //Repository connected to MyContext
  56.  
  57.         var user = new ApplicationUser
  58.         {
  59.             UserName = "SomeEmail@gmail.com",
  60.             Email = "SomeEmail@gmail.com",
  61.             EmailConfirmed = true
  62.         };
  63.  
  64.         userManager.Create(user, "APASSWORDHERE");
  65.  
  66.         if (roleManager.Roles.Count() == 0)
  67.         {
  68.             roleManager.Create(new IdentityRole { Name = "SuperAdmin" });
  69.             roleManager.Create(new IdentityRole { Name = "Admin" });
  70.             roleManager.Create(new IdentityRole { Name = "CLevel" });
  71.             roleManager.Create(new IdentityRole { Name = "DistrictManager" });
  72.             roleManager.Create(new IdentityRole { Name = "AreaManager" });
  73.             roleManager.Create(new IdentityRole { Name = "OfficeStaff" });
  74.             roleManager.Create(new IdentityRole { Name = "Contractor" });
  75.             roleManager.Create(new IdentityRole { Name = "Client" });
  76.         }
  77.  
  78.         ApplicationUser adminIdentityUser = userManager.FindByName("SomeEmail@gmail.com");
  79.  
  80.         userManager.AddToRoles(adminIdentityUser.Id, new string[] { "SuperAdmin", "Admin" });
  81.  
  82.         User adminUser = new User
  83.         {
  84.             EmailAddress = adminIdentityUser.Email,
  85.             FName = "Admin",
  86.             Id = Guid.Parse(adminIdentityUser.Id),
  87.             JoinDate = DateTime.Now.AddYears(-3),
  88.             LName = "User"
  89.         };
  90.  
  91.         userContext.Create(adminUser);
  92.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top