diff --git a/Sources/EFManager/ManagerTranslate.cs b/Sources/EFManager/ManagerTranslate.cs deleted file mode 100644 index 6f52933..0000000 --- a/Sources/EFManager/ManagerTranslate.cs +++ /dev/null @@ -1,61 +0,0 @@ -using EFlib; -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EFManager -{ - public static class ManagerTranslate - { - // Champion - public static EFChampion toEF(this Champion Champ, SQLiteContext context) - { - - EFChampion? EfChampion = context.Champions.Find(Champ.Name); - if (EfChampion == null) - { - EfChampion = new() - { - Name = Champ.Name, - Bio = Champ.Bio, - Icon = Champ.Icon, - Class = Champ.Class, - Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 }, - }; - EfChampion.Skills = Champ.Skills.Select(Skill => Skill.toEF(EfChampion, context)).ToList(); - EfChampion.Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList(); - - } - return EfChampion; - - } - - public static Champion toModel(this EFChampion EFChamp) - { - var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio); - if (EFChamp.Skills != null) foreach (var s in EFChamp.Skills) { champion.AddSkill(skill.toModel()); } - if (EFChamp.Characteristics != null) foreach (var c in EFChamp.Characteristics) { champion.AddCharacteristics(c.toModel()); } - return champion; - } - - // Characteristics - - // Skin - public static EFSkin toEF(this Skin Skin) => new EFSkin { Name = Skin.Name, Description = Skin.Description, Icon = Skin.Icon, Price = Skin.Price }; - public static Skin toModel(this EFSkin EFSkin) => new Skin(EFSkin.Name, EFSkin.Champion.toModel()); - - // Skill - - // LargeImage - public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 }; - public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64); - - // Rune - - // RunePage - - } -} diff --git a/Sources/EFMapping/EFChampionMapper.cs b/Sources/EFMapping/EFChampionMapper.cs index db8bc97..58e9bd0 100644 --- a/Sources/EFMapping/EFChampionMapper.cs +++ b/Sources/EFMapping/EFChampionMapper.cs @@ -1,8 +1,40 @@ -namespace EFMapping +using EFlib; +using Model; + +namespace EFMapping { - public class EFChampionMapper + public static class EFChampionMapper { + public static EFChampion toEF(this Champion Champ, SQLiteContext context) + { + + EFChampion? EfChampion = context.Champions.Find(Champ.Name); + if (EfChampion == null) + { + EfChampion = new() + { + Name = Champ.Name, + Bio = Champ.Bio, + Icon = Champ.Icon, + Class = Champ.Class, + Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 }, + Skills = Champ.Skills.Select(Skill => Skill.toEF(EfChampion, context)).ToList(), + Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList() + + }; + + } + return EfChampion; + + } + public static Champion toModel(this EFChampion EFChamp) + { + var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio); + if (EFChamp.Skills != null) foreach (var skill in EFChamp.Skills) { champion.AddSkill(skill.toModel()); } + if (EFChamp.Characteristics != null) foreach (var charac in EFChamp.Characteristics) { champion.AddCharacteristics(charac.toModel()); } + return champion; + } } } \ No newline at end of file diff --git a/Sources/EFMapping/EFCharacteristicsMapper.cs b/Sources/EFMapping/EFCharacteristicsMapper.cs new file mode 100644 index 0000000..4c23307 --- /dev/null +++ b/Sources/EFMapping/EFCharacteristicsMapper.cs @@ -0,0 +1,31 @@ +using EFlib; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EFMapping +{ + public static class EFCharacteristicsMapper + { + public static EFCharacteristics toEF(this KeyValuePair item, EFChampion champion, SQLiteContext context) + { + var charac = context.Characteristics.Find(item.Key, champion.Name); + if (charac == null) + { + return new() + { + Name = item.Key, + Value = item.Value, + NameChampion = champion.Name + }; + } + return charac; + } + + public static Tuple toModel(this EFCharacteristics charac) + => new(charac.Name, charac.Value); + } +} diff --git a/Sources/EFMapping/EFLargeImageMapper.cs b/Sources/EFMapping/EFLargeImageMapper.cs new file mode 100644 index 0000000..b9e02e7 --- /dev/null +++ b/Sources/EFMapping/EFLargeImageMapper.cs @@ -0,0 +1,16 @@ +using EFlib; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EFMapping +{ + public static class EFLargeImageMapper + { + public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 }; + public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64); + } +} diff --git a/Sources/EFMapping/EFMapping.csproj b/Sources/EFMapping/EFMapping.csproj index bafd05b..6791075 100644 --- a/Sources/EFMapping/EFMapping.csproj +++ b/Sources/EFMapping/EFMapping.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/Sources/EFMapping/EFRuneMapper.cs b/Sources/EFMapping/EFRuneMapper.cs index dc273b0..42e9ad2 100644 --- a/Sources/EFMapping/EFRuneMapper.cs +++ b/Sources/EFMapping/EFRuneMapper.cs @@ -8,5 +8,6 @@ namespace EFMapping { public class EFRuneMapper { + // TO DO } } diff --git a/Sources/EFMapping/EFRunePageMapper.cs b/Sources/EFMapping/EFRunePageMapper.cs index 4440c70..dfae0fe 100644 --- a/Sources/EFMapping/EFRunePageMapper.cs +++ b/Sources/EFMapping/EFRunePageMapper.cs @@ -8,5 +8,6 @@ namespace EFMapping { public class EFRunePageMapper { + // TO DO } } diff --git a/Sources/EFMapping/EFSkillMapper.cs b/Sources/EFMapping/EFSkillMapper.cs index ee16ed5..e244c43 100644 --- a/Sources/EFMapping/EFSkillMapper.cs +++ b/Sources/EFMapping/EFSkillMapper.cs @@ -1,4 +1,6 @@ -using System; +using EFlib; +using Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,27 @@ using System.Threading.Tasks; namespace EFMapping { - public class EFSkillMapper + public static class EFSkillMapper { + public static EFSkill toEF(this Skill skill, EFChampion champion, SQLiteContext context) + { + var EfSkill = context.Skills.Find(skill.Name); + if (EfSkill == null) + { + return new() + { + Name = skill.Name, + Description = skill.Description, + Type = skill.Type, + Champion = new List() { champion } + }; + } + EfSkill!.Champions?.Add(champion); + return EfSkill; + } + + + public static Skill toModel(this EFSkill skill) + => new(skill.Name, skill.Type, skill.Description); } } diff --git a/Sources/EFMapping/EFSkinMapper.cs b/Sources/EFMapping/EFSkinMapper.cs index 90a260b..2dda7c0 100644 --- a/Sources/EFMapping/EFSkinMapper.cs +++ b/Sources/EFMapping/EFSkinMapper.cs @@ -1,4 +1,6 @@ -using System; +using EFlib; +using Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,22 @@ using System.Threading.Tasks; namespace EFMapping { - public class EFSkinMapper + public static class EFSkinMapper { + public static EFSkin toEF(this Skin skin, SQLiteContext? context = null) + { + return new() + { + Name = skin.Name, + Description = skin.Description, + Icon = skin.Icon, + Price = skin.Price, + Image = new() { Id = Guid.NewGuid(), Base64 = skin.Image.Base64 }, + NameChampion = skin.Champion.Name, + Champion = context?.Champions.Find(skin.Champion.Name) ?? skin.Champion.toEF(context), + }; + } + + public static Skin toModel(this EFSkin Skin)=> new(Skin.Name, Skin.Champion.toModel(), Skin.Price, null, Skin.Description); } } diff --git a/Sources/EFlib/EFChampion.cs b/Sources/EFlib/EFChampion.cs index ec527a1..90b8317 100644 --- a/Sources/EFlib/EFChampion.cs +++ b/Sources/EFlib/EFChampion.cs @@ -12,7 +12,7 @@ namespace EFlib { /**** Only Attributs ****/ [Key] - [MaxLength(256)] + [MaxLength(250)] public string Name { get; set; } [MaxLength(500)] diff --git a/Sources/EFlib/EFCharacteristics.cs b/Sources/EFlib/EFCharacteristics.cs index 7a48513..db21c6d 100644 --- a/Sources/EFlib/EFCharacteristics.cs +++ b/Sources/EFlib/EFCharacteristics.cs @@ -11,14 +11,13 @@ namespace EFlib public class EFCharacteristics { [Key] - public int Id { get; set; } - + [MaxLength(250)] public string Name { get; set; } + [Required] public int Value { get; set; } - - // Clé étrangère vers l'entité parente - public EFChampion EFChampion { get; set; } - [ForeignKey("EFChampion")] - public string EFChampionName { get; set; } + [Required] + public string NameChampion { get; set; } + [ForeignKey("NameChampion")] + public EFChampion Champion { get; set; } } } diff --git a/Sources/EFlib/Migrations/20230318182850_myMigrations.Designer.cs b/Sources/EFlib/Migrations/20230321114141_myMigration.Designer.cs similarity index 90% rename from Sources/EFlib/Migrations/20230318182850_myMigrations.Designer.cs rename to Sources/EFlib/Migrations/20230321114141_myMigration.Designer.cs index 30f23be..3a85b19 100644 --- a/Sources/EFlib/Migrations/20230318182850_myMigrations.Designer.cs +++ b/Sources/EFlib/Migrations/20230321114141_myMigration.Designer.cs @@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EFlib.Migrations { [DbContext(typeof(SQLiteContext))] - [Migration("20230318182850_myMigrations")] - partial class myMigrations + [Migration("20230321114141_myMigration")] + partial class myMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -23,7 +23,7 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFChampion", b => { b.Property("Name") - .HasMaxLength(256) + .HasMaxLength(250) .HasColumnType("TEXT"); b.Property("Bio") @@ -50,24 +50,20 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFCharacteristics", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("EFChampionName") - .IsRequired() + b.Property("Name") + .HasMaxLength(250) .HasColumnType("TEXT"); - b.Property("Name") + b.Property("NameChampion") .IsRequired() .HasColumnType("TEXT"); b.Property("Value") .HasColumnType("INTEGER"); - b.HasKey("Id"); + b.HasKey("Name"); - b.HasIndex("EFChampionName"); + b.HasIndex("NameChampion"); b.ToTable("EFCharacteristics"); }); @@ -154,13 +150,13 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFCharacteristics", b => { - b.HasOne("EFlib.EFChampion", "EFChampion") + b.HasOne("EFlib.EFChampion", "Champion") .WithMany("Characteristics") - .HasForeignKey("EFChampionName") + .HasForeignKey("NameChampion") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("EFChampion"); + b.Navigation("Champion"); }); modelBuilder.Entity("EFlib.EFSkill", b => diff --git a/Sources/EFlib/Migrations/20230318182850_myMigrations.cs b/Sources/EFlib/Migrations/20230321114141_myMigration.cs similarity index 90% rename from Sources/EFlib/Migrations/20230318182850_myMigrations.cs rename to Sources/EFlib/Migrations/20230321114141_myMigration.cs index 2f8838f..1536631 100644 --- a/Sources/EFlib/Migrations/20230318182850_myMigrations.cs +++ b/Sources/EFlib/Migrations/20230321114141_myMigration.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace EFlib.Migrations { /// - public partial class myMigrations : Migration + public partial class myMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -27,7 +27,7 @@ namespace EFlib.Migrations name: "Champions", columns: table => new { - Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Name = table.Column(type: "TEXT", maxLength: 250, nullable: false), Bio = table.Column(type: "TEXT", maxLength: 500, nullable: false), Icon = table.Column(type: "TEXT", nullable: false), Class = table.Column(type: "INTEGER", nullable: false), @@ -48,18 +48,16 @@ namespace EFlib.Migrations name: "EFCharacteristics", columns: table => new { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 250, nullable: false), Value = table.Column(type: "INTEGER", nullable: false), - EFChampionName = table.Column(type: "TEXT", nullable: false) + NameChampion = table.Column(type: "TEXT", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_EFCharacteristics", x => x.Id); + table.PrimaryKey("PK_EFCharacteristics", x => x.Name); table.ForeignKey( - name: "FK_EFCharacteristics_Champions_EFChampionName", - column: x => x.EFChampionName, + name: "FK_EFCharacteristics_Champions_NameChampion", + column: x => x.NameChampion, principalTable: "Champions", principalColumn: "Name", onDelete: ReferentialAction.Cascade); @@ -118,9 +116,9 @@ namespace EFlib.Migrations column: "ImageId"); migrationBuilder.CreateIndex( - name: "IX_EFCharacteristics_EFChampionName", + name: "IX_EFCharacteristics_NameChampion", table: "EFCharacteristics", - column: "EFChampionName"); + column: "NameChampion"); migrationBuilder.CreateIndex( name: "IX_Skills_EFChampionName", diff --git a/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs index 0b9aaa1..468f77d 100644 --- a/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs +++ b/Sources/EFlib/Migrations/SQLiteContextModelSnapshot.cs @@ -20,7 +20,7 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFChampion", b => { b.Property("Name") - .HasMaxLength(256) + .HasMaxLength(250) .HasColumnType("TEXT"); b.Property("Bio") @@ -47,24 +47,20 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFCharacteristics", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("EFChampionName") - .IsRequired() + b.Property("Name") + .HasMaxLength(250) .HasColumnType("TEXT"); - b.Property("Name") + b.Property("NameChampion") .IsRequired() .HasColumnType("TEXT"); b.Property("Value") .HasColumnType("INTEGER"); - b.HasKey("Id"); + b.HasKey("Name"); - b.HasIndex("EFChampionName"); + b.HasIndex("NameChampion"); b.ToTable("EFCharacteristics"); }); @@ -151,13 +147,13 @@ namespace EFlib.Migrations modelBuilder.Entity("EFlib.EFCharacteristics", b => { - b.HasOne("EFlib.EFChampion", "EFChampion") + b.HasOne("EFlib.EFChampion", "Champion") .WithMany("Characteristics") - .HasForeignKey("EFChampionName") + .HasForeignKey("NameChampion") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("EFChampion"); + b.Navigation("Champion"); }); modelBuilder.Entity("EFlib.EFSkill", b => diff --git a/Sources/EFlib/SQLiteContext.cs b/Sources/EFlib/SQLiteContext.cs index 2898495..cd6e1ce 100644 --- a/Sources/EFlib/SQLiteContext.cs +++ b/Sources/EFlib/SQLiteContext.cs @@ -6,6 +6,8 @@ namespace EFlib { /**** Attributs ****/ public DbSet Champions { get; set; } + public DbSet Characteristics { get; set; } + public DbSet LargeImages { get; set; } public DbSet Skins { get; set; } public DbSet Skills { get; set; } diff --git a/Sources/EFlib/projet.dbloulou.db b/Sources/EFlib/projet.dbloulou.db index 327bfab..17e385d 100644 Binary files a/Sources/EFlib/projet.dbloulou.db and b/Sources/EFlib/projet.dbloulou.db differ diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 250b7ea..874d5f0 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestManagerEF", "Tests\Test EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFMapping", "EFMapping\EFMapping.csproj", "{0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -93,6 +95,10 @@ Global {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Debug|Any CPU.Build.0 = Debug|Any CPU {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.Build.0 = Release|Any CPU + {0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE