Exemplo n.º 1
0
 public static void EnsureSeeded(this TrainDTrainorContext context)
 {
     if (context.CheckTableExists <Role>())
     {
         if (!context.Roles.Any())
         {
             var roles = JsonConvert.DeserializeObject <List <Role> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "Roles.json"));
             context.AddRange(roles);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <User>())
     {
         if (!context.Users.Any())
         {
             var users = JsonConvert.DeserializeObject <List <User> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "Users.json"));
             context.AddRange(users);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <UserProfile>())
     {
         if (!context.UserProfiles.Any())
         {
             var usersprofile = JsonConvert.DeserializeObject <List <UserProfile> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "UsersProfile.json"));
             context.AddRange(usersprofile);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <UserRole>())
     {
         if (!context.UserRoles.Any())
         {
             var userroles = JsonConvert.DeserializeObject <List <UserRole> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "UserRoles.json"));
             context.AddRange(userroles);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <RefreshToken>())
     {
         if (!context.RefreshTokens.Any())
         {
             var userroles = JsonConvert.DeserializeObject <List <RefreshToken> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "RefreshToken.json"));
             context.AddRange(userroles);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <UserLogin>())
     {
         if (!context.UserLogins.Any())
         {
             var userroles = JsonConvert.DeserializeObject <List <UserLogin> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "UserLogins.json"));
             context.AddRange(userroles);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <Training>())
     {
         if (!context.Training.Any())
         {
             var trainings = JsonConvert.DeserializeObject <List <Training> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "Training.json"));
             context.AddRange(trainings);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <Level>())
     {
         if (!context.Levels.Any())
         {
             var trainings = JsonConvert.DeserializeObject <List <Level> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "Levels.json"));
             context.AddRange(trainings);
             context.SaveChanges();
         }
     }
     if (context.CheckTableExists <Country>())
     {
         if (!context.Countries.Any())
         {
             var countries = JsonConvert.DeserializeObject <List <Country> >(File.ReadAllText("DataSeeds" + Path.DirectorySeparatorChar + "Countries.json"));
             context.AddRange(countries);
             context.SaveChanges();
         }
     }
 }