title: Create roles in ASP.NET
body: <p>I am trying to create different roles for my website but they aren't saving to the database. I have used this code before on a different project where it worked fine but for some reason it doesn't work on this one. </p>
  
  <p>I have looked at other similar questions on here and tried different ways to get it work working with no luck. It may be something really obvious but any help would be greatly appreciated.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class DatabaseInitializer : DropCreateDatabaseIfModelChanges&lt;ApplicationDbContext&gt;
  {
      protected override void Seed(ApplicationDbContext context)
      {
          if (!context.Users.Any())
          {
              var roleManager = new RoleManager&lt;IdentityRole&gt;(new RoleStore&lt;IdentityRole&gt;(context));
              var userManager = new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;(context));
  
              if (!roleManager.RoleExists("Admin"))
              {
                  var roleResults = roleManager.Create(new IdentityRole("Admin"));
              }
  
              if (!roleManager.RoleExists("Customer"))
              {
                  var roleResults = roleManager.Create(new IdentityRole("Customer"));
              }
  
              var user = userManager.FindByName("admin@admin.com");
              if (user == null)
              {
                  var newUser = new Admin()
                  {
                      FirstName = "Thomas",
                      LastName = "Green",
                      Email = "admin@admin.com",
                      UserName = "admin@admin.com",
                  };
  
                  userManager.Create(newUser, "Admin12345");
                  userManager.AddToRole(newUser.Id, "Admin");
  
              }
  
              var user2 = userManager.FindByName("customer@test.com");
              if (user2 == null)
              {
                  var newUser2 = new Customer()
                  {
                      FirstName = "Luke",
                      LastName = "Red",
                      Address = "5 Hilton Court",
                      City = "Glasgow",
                      Postcode = "KA21 6HX",
                      UserName = "customer@test.com",
                      Email = "customer@test.com",
  
                  };
                  userManager.Create(newUser2, "Password");
                  userManager.AddToRole(newUser2.Id, "Customer");
              }
          }
  
          base.Seed(context);
          context.SaveChanges();
      }
  }
  </code></pre>