//Adding seed data when the application starts public void SeedAdminData() { var adminEmail = "[email protected]"; var adminPassword = "******"; var adminUserId = string.Empty; if (Users.Any(u => u.Email.Equals(adminEmail))) { adminUserId = (Users.SingleOrDefault(u => u.Email.Equals(adminEmail))).Id; } else { var user = new VODUser { Email = adminEmail, UserName = adminEmail, NormalizedEmail = adminEmail.ToUpper(), NormalizedUserName = adminEmail.ToUpper() }; var passwordHasher = new PasswordHasher <VODUser>(); user.PasswordHash = passwordHasher.HashPassword(user, adminPassword); Users.Add(user); SaveChanges(); adminUserId = (Users.SingleOrDefault(u => u.Email.Equals(adminEmail))).Id; var adminRoleName = "Admin"; var adminRole = Roles.SingleOrDefault(r => r.Name.ToLower().Equals(adminRoleName.ToLower())); if (adminRole == default) { Roles.Add(new IdentityRole() { Name = adminRoleName, NormalizedName = adminRoleName.ToUpper(), Id = "1" }); SaveChanges(); adminRole = Roles.SingleOrDefault(r => r.Name.ToLower().Equals(adminRoleName.ToLower())); } if (!adminUserId.Equals(string.Empty)) { if (adminRole != default) { var userRoleExists = UserRoles.Any(ur => ur.RoleId.Equals(adminRole.Id) && ur.UserId.Equals(adminUserId)); if (!userRoleExists) { UserRoles.Add(new IdentityUserRole <string> { RoleId = adminRole.Id, UserId = adminUserId }); } } } var claimType = "Admin"; var userClaimExists = UserClaims.Any(uc => uc.ClaimType.ToLower().Equals(claimType.ToLower()) && uc.UserId.Equals(adminUserId)); if (!userClaimExists) { UserClaims.Add(new IdentityUserClaim <string> { ClaimType = claimType, ClaimValue = "true", UserId = adminUserId }); } claimType = "VODUser"; userClaimExists = UserClaims.Any(uc => uc.ClaimType.ToLower().Equals(claimType.ToLower()) && uc.UserId.Equals(adminUserId)); if (!userClaimExists) { UserClaims.Add(new IdentityUserClaim <string> { ClaimType = claimType, ClaimValue = "true", UserId = adminUserId }); } } SaveChanges(); }