|
@@ -2,27 +2,23 @@
|
|
|
using Domain.Weapons;
|
|
using Domain.Weapons;
|
|
|
using Domain.XML_Model;
|
|
using Domain.XML_Model;
|
|
|
using Infrastructure;
|
|
using Infrastructure;
|
|
|
-using System.Collections.Generic;
|
|
|
|
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
|
|
|
+using System.Numerics;
|
|
|
|
|
|
|
|
namespace DataLayer;
|
|
namespace DataLayer;
|
|
|
|
|
|
|
|
public static class DbContextInitializer
|
|
public static class DbContextInitializer
|
|
|
{
|
|
{
|
|
|
- public static void Initialize(DeathwatchDbContext context, string filepath = null)
|
|
|
|
|
|
|
+ private static bool _isSeeded = false;
|
|
|
|
|
+ public static async Task Initialize(DeathwatchDbContext context, string? filepath = null)
|
|
|
{
|
|
{
|
|
|
- context.Database.EnsureCreated();
|
|
|
|
|
-
|
|
|
|
|
- // Look for any students.
|
|
|
|
|
- if (context.Players.Any()) return; // DB has been seeded
|
|
|
|
|
-
|
|
|
|
|
- var weapon = new Weapon
|
|
|
|
|
- {
|
|
|
|
|
- At = "test",
|
|
|
|
|
- Range = 30,
|
|
|
|
|
- Attribute = "CT",
|
|
|
|
|
- Type = "RANGE"
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ await context.Database.EnsureCreatedAsync();
|
|
|
|
|
+ await SeedDatabase(context, filepath);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private static async Task SeedPlayers(DeathwatchDbContext context)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (context.Players.Any()) return;
|
|
|
var players = new[]
|
|
var players = new[]
|
|
|
{
|
|
{
|
|
|
new Player
|
|
new Player
|
|
@@ -37,223 +33,260 @@ public static class DbContextInitializer
|
|
|
PER = 43,
|
|
PER = 43,
|
|
|
FM = 43,
|
|
FM = 43,
|
|
|
SOC = 40,
|
|
SOC = 40,
|
|
|
- Weapons = new List<Weapon> { weapon }
|
|
|
|
|
|
|
+ Weapons = new List<Weapon>
|
|
|
|
|
+ {
|
|
|
|
|
+ new()
|
|
|
|
|
+ {
|
|
|
|
|
+ At = "test",
|
|
|
|
|
+ Range = 30,
|
|
|
|
|
+ Attribute = "CT",
|
|
|
|
|
+ Type = "RANGE"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
- foreach (var player in players) context.Players.Add(player);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
-
|
|
|
|
|
- SeedDatabase(context, filepath);
|
|
|
|
|
|
|
+ foreach (var player in players) await context.Players.AddAsync(player);
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void SeedDatabase(DeathwatchDbContext context, string filesPath = null)
|
|
|
|
|
|
|
+ public static async Task SeedDatabase(DeathwatchDbContext context, string? filesPath = null)
|
|
|
{
|
|
{
|
|
|
- // Define the paths to the XML files
|
|
|
|
|
-
|
|
|
|
|
- //string accessoireFilePath = Path.Combine("XML", "Accessoires.xml");
|
|
|
|
|
- //string ameliorationFilePath = Path.Combine("XML", "Ameliorations.xml");
|
|
|
|
|
- //string extensionFilePath = Path.Combine("XML", "Extensions.xml");
|
|
|
|
|
- if (!string.IsNullOrEmpty(filesPath))
|
|
|
|
|
- {
|
|
|
|
|
- var roots = new List<Root>();
|
|
|
|
|
- try
|
|
|
|
|
- {
|
|
|
|
|
- // Deserialize the XML files
|
|
|
|
|
- GetRootsElements(roots, filesPath);
|
|
|
|
|
- ExtractFromRoot(context, roots);
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- catch (Exception e)
|
|
|
|
|
- {
|
|
|
|
|
- throw;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (_isSeeded) return;
|
|
|
|
|
+ await SeedPlayers(context);
|
|
|
|
|
+
|
|
|
|
|
+ if (string.IsNullOrEmpty(filesPath)) return;
|
|
|
|
|
+ var roots = new List<Root>();
|
|
|
|
|
+ GetRootsElements(roots, filesPath);
|
|
|
|
|
+ await ExtractFromRootAsync(context, roots);
|
|
|
|
|
+ _isSeeded = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private static void GetRootsElements(List<Root> roots, string filesPath)
|
|
private static void GetRootsElements(List<Root> roots, string filesPath)
|
|
|
{
|
|
{
|
|
|
var fileExist = Directory.Exists(filesPath);
|
|
var fileExist = Directory.Exists(filesPath);
|
|
|
- if (fileExist)
|
|
|
|
|
- {
|
|
|
|
|
- var xmlFiles = Directory.GetFiles(filesPath, "*.xml");
|
|
|
|
|
|
|
+ if (!fileExist) return;
|
|
|
|
|
+ var xmlFiles = Directory.GetFiles(filesPath, "*.xml");
|
|
|
|
|
|
|
|
- foreach (var xmlFile in xmlFiles)
|
|
|
|
|
- {
|
|
|
|
|
- var root = XmlHelper.DeserializeXmlFile<Root>(xmlFile);
|
|
|
|
|
- roots.Add(root);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ roots.AddRange(xmlFiles.Select(XmlHelper.DeserializeXmlFile<Root>));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private static void ExtractFromRoot(DeathwatchDbContext context, List<Root> roots)
|
|
|
|
|
|
|
+ private static async Task ExtractFromRootAsync(DeathwatchDbContext context, List<Root> roots)
|
|
|
{
|
|
{
|
|
|
- foreach (var root in roots)
|
|
|
|
|
|
|
+ foreach (var root in roots.OfType<Root>())
|
|
|
{
|
|
{
|
|
|
- if (root != null)
|
|
|
|
|
- {
|
|
|
|
|
- if (root.Extensions != null && root.Extensions != null && !context.Extensions.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Extensions.AddRange(root.Extensions);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Accessoires.Any())
|
|
|
|
|
+ context.Accessoires.AddRange(root.AccessoiresArmes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in
|
|
|
|
|
+ root.AccessoiresArmes.Where(item => !context.Accessoires.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Accessoires.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.AccessoiresArmes != null && root.AccessoiresArmes != null && !context.Accessoires.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Accessoires.AddRange(root.AccessoiresArmes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Améliorations.Any())
|
|
|
|
|
+ context.Améliorations.AddRange(root.Améliorations);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Améliorations.Where(item => !context.Améliorations.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Améliorations.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Améliorations != null && root.Améliorations != null && !context.Améliorations.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Améliorations.AddRange(root.Améliorations);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Archétypes.Any())
|
|
|
|
|
+ context.Archétypes.AddRange(root.Archétypes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Archétypes.Where(item => !context.Archétypes.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Archétypes.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Archétypes != null && root.Archétypes != null && !context.Archétypes.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Archétypes.AddRange(root.Archétypes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Armes.Any())
|
|
|
|
|
+ context.Armes.AddRange(root.Armes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Armes.Where(item => !context.Armes.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Armes.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Armes != null && root.Armes != null && !context.Armes.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Armes.AddRange(root.Armes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Armures.Any())
|
|
|
|
|
+ context.Armures.AddRange(root.Armures);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Armures.Where(item => !context.Armures.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Armures.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Armures != null && root.Armures != null && !context.Armures.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Armures.AddRange(root.Armures);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Assermentations.Any())
|
|
|
|
|
+ context.Assermentations.AddRange(root.Assermentations);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Assermentations.Where(item =>
|
|
|
|
|
+ !context.Assermentations.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Assermentations.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Attributs.Any())
|
|
|
|
|
+ context.Attributs.AddRange(root.AttributsArmes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.AttributsArmes.Where(item => !context.Attributs.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Attributs.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Carrières.Any())
|
|
|
|
|
+ context.Carrières.AddRange(root.Carrières);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Carrières.Where(item => !context.Carrières.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Carrières.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Competences.Any())
|
|
|
|
|
+ context.Competences.AddRange(root.Competences);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Competences.Where(item => !context.Competences.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Competences.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Coordonnées.Any())
|
|
|
|
|
+ context.Coordonnées.AddRange(root.Coordonnées);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Coordonnées.Where(item => !context.Coordonnées.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Coordonnées.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Cybernétiques.Any())
|
|
|
|
|
+ context.Cybernétiques.AddRange(root.Cybernétiques);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Cybernétiques.Where(item => !context.Cybernétiques.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Cybernétiques.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Disciplines.Any())
|
|
|
|
|
+ context.Disciplines.AddRange(root.Disciplines);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Disciplines.Where(item => !context.Disciplines.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Disciplines.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Divinations.Any())
|
|
|
|
|
+ context.Divinations.AddRange(root.Divinations);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Divinations.Where(item => !context.Divinations.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Divinations.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Assermentations != null && root.Assermentations != null && !context.Assermentations.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Assermentations.AddRange(root.Assermentations);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.AttributsArmes != null && root.AttributsArmes != null && !context.Attributs.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Attributs.AddRange(root.AttributsArmes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Equipements.Any())
|
|
|
|
|
+ context.Equipements.AddRange(root.Equipements);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Equipements.Where(item => !context.Equipements.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Equipements.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Carrières != null && root.Carrières != null && !context.Carrières.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Carrières.AddRange(root.Carrières);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Competences != null && root.Competences != null && !context.Competences.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Competences.AddRange(root.Competences);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Implants.Any())
|
|
|
|
|
+ context.Implants.AddRange(root.Implants);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Implants.Where(item => !context.Implants.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Implants.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Coordonnées != null && root.Coordonnées != null && !context.Coordonnées.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Coordonnées.AddRange(root.Coordonnées);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Cybernétiques != null && root.Cybernétiques != null && !context.Cybernétiques.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Cybernétiques.AddRange(root.Cybernétiques);
|
|
|
|
|
|
|
+ if (!context.Mondes.Any())
|
|
|
|
|
+ context.Mondes.AddRange(root.Mondes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Mondes.Where(item => !context.Mondes.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Mondes.AddAsync(item);
|
|
|
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Disciplines != null && root.Disciplines != null && !context.Disciplines.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Disciplines.AddRange(root.Disciplines);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Mutations.Any())
|
|
|
|
|
+ context.Mutations.AddRange(root.Mutations);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Mutations.Where(item => !context.Mutations.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Mutations.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Divinations != null && root.Divinations != null && !context.Divinations.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Divinations.AddRange(root.Divinations);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Equipements != null && root.Equipements != null && !context.Equipements.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Equipements.AddRange(root.Equipements);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Pouvoirs.Any())
|
|
|
|
|
+ context.Pouvoirs.AddRange(root.Pouvoirs);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Pouvoirs.Where(item => !context.Pouvoirs.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Pouvoirs.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Implants != null && root.Implants != null && !context.Implants.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Implants.AddRange(root.Implants);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Mondes != null && root.Mondes != null && !context.Mondes.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Mondes.AddRange(root.Mondes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Promotions.Any())
|
|
|
|
|
+ context.Promotions.AddRange(root.Promotions);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Promotions.Where(item => !context.Promotions.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Promotions.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Mutations != null && root.Mutations != null && !context.Mutations.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Mutations.AddRange(root.Mutations);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Pouvoirs != null && root.Pouvoirs != null && !context.Pouvoirs.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Pouvoirs.AddRange(root.Pouvoirs);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Seuils.Any())
|
|
|
|
|
+ context.Seuils.AddRange(root.SeuilsXp);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.SeuilsXp.Where(item => !context.Seuils.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Seuils.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Promotions != null && root.Promotions != null && !context.Promotions.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Promotions.AddRange(root.Promotions);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.SeuilsXp != null && root.SeuilsXp != null && !context.Seuils.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Seuils.AddRange(root.SeuilsXp);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Sousmondes.Any())
|
|
|
|
|
+ context.Sousmondes.AddRange(root.Sousmondes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Sousmondes.Where(item => !context.Sousmondes.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Sousmondes.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Sousmondes != null && root.Sousmondes != null && !context.Sousmondes.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Sousmondes.AddRange(root.Sousmondes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Talents != null && root.Talents != null && !context.Talents.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Talents.AddRange(root.Talents);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Traits.Any())
|
|
|
|
|
+ context.Traits.AddRange(root.Traits);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Traits.Where(item => !context.Traits.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Traits.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.Traits != null && root.Traits != null && !context.Traits.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Traits.AddRange(root.Traits);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.Troubles != null && root.Troubles != null && !context.Troubles.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.Troubles.AddRange(root.Troubles);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!context.Troubles.Any())
|
|
|
|
|
+ context.Troubles.AddRange(root.Troubles);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Troubles.Where(item => !context.Troubles.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.Troubles.AddAsync(item);
|
|
|
|
|
|
|
|
- if (root.TypeMondes != null && root.TypeMondes != null && !context.TypeMondes.Any())
|
|
|
|
|
- {
|
|
|
|
|
- context.TypeMondes.AddRange(root.TypeMondes);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.TypeMondes.Any())
|
|
|
|
|
+ context.TypeMondes.AddRange(root.TypeMondes);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.TypeMondes.Where(item => !context.TypeMondes.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.TypeMondes.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
|
|
|
- if (root.TypesNom != null && root.TypesNom != null && !context.TypesNom.Any())
|
|
|
|
|
|
|
+ if (!context.TypesNom.Any())
|
|
|
|
|
+ context.TypesNom.AddRange(root.TypesNom);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.TypesNom.Where(item => !context.TypesNom.Any(e => e.Id == item.Id)))
|
|
|
|
|
+ await context.TypesNom.AddAsync(item);
|
|
|
|
|
+
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
|
|
+ if (!context.Talents.Any())
|
|
|
|
|
+ context.Talents.AddRange(root.Talents);
|
|
|
|
|
+ else
|
|
|
|
|
+ foreach (var item in root.Talents)
|
|
|
{
|
|
{
|
|
|
- context.TypesNom.AddRange(root.TypesNom);
|
|
|
|
|
- context.SaveChanges();
|
|
|
|
|
|
|
+ if (!context.Talents.AsNoTracking().Any(e => e.Id == item.Id))
|
|
|
|
|
+ await context.Talents.AddAsync(item);
|
|
|
|
|
+ await context.SaveChangesAsync();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|