public static void SeedAdmin() { using (TorshiaDbContext context = new TorshiaDbContext()) { string userRoleId = GetRoleId("User"); string adminRoleId = GetRoleId("Admin"); var userRoles = new HashSet <UserRole>() { new UserRole { RoleId = userRoleId }, new UserRole { RoleId = adminRoleId } }; context.Users.Add(new User { Email = "*****@*****.**", Password = HashPassword("admin"), Username = "******", Roles = userRoles }); context.SaveChanges(); } }
private static void AddRoleIfNotExists(string roleName) { using (TorshiaDbContext context = new TorshiaDbContext()) { if (!context.Roles.Any(r => r.Name == roleName)) { context.Roles.Add(new Role { Name = roleName }); } context.SaveChanges(); } }