diff --git a/Sources/Client/StubEntityInit.cs b/Sources/Client/StubEntityInit.cs index 874ff27..172b20b 100644 --- a/Sources/Client/StubEntityInit.cs +++ b/Sources/Client/StubEntityInit.cs @@ -9,17 +9,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Api_lol.Factories; +using Api_lol.Controllers; namespace Client { public class StubEntityInit { private Factories facto = new Factories(); - + private StubData data = new StubData(); public async void AddAllChampions() { - StubData data = new StubData(); var liste = await data.ChampionsMgr.GetItems(0,await data.ChampionsMgr.GetNbItems()); var listeDto = liste.ToList().Select(model => facto.ChampionModelToEntity(model)); @@ -27,6 +27,8 @@ namespace Client { foreach(var item in listeDto) { + int ImageId = AddOneImage(); + item.ImageId = ImageId; db.Add(item); } db.SaveChanges(); @@ -35,9 +37,7 @@ namespace Client public async void AddAllSkins() { - StubData data = new StubData(); var skins = await data.SkinsMgr.GetItems(0, await data.SkinsMgr.GetNbItems()); - //var skinsDto = skins.ToList().Select(model => facto.SkinsModelToEntity(model)); using (BDDContext db = new BDDContext()) { @@ -45,17 +45,59 @@ namespace Client { int idChampion = (db.Champions.Where(m => m.Name == item.Champion.Name).First()).Id; EntitySkins skin = facto.SkinsModelToEntity(item,idChampion); + + int idImage = AddOneImage(); + skin.ImageId = idImage; db.Add(skin); } db.SaveChanges(); } } + public int AddOneImage() + { + Random aleatoire = new Random(); + EntityLargeImage tmpImage = new EntityLargeImage(); + tmpImage.Base64 = "Inconnu"; + tmpImage.Id = aleatoire.Next(); + + using (BDDContext db = new BDDContext()) + { + db.Add(tmpImage); + db.SaveChanges(); + } + return tmpImage.Id; + } + + public async void AddAllRunes() + { + var runes = await data.RunesMgr.GetItems(0, await data.RunesMgr.GetNbItems()); + + using (BDDContext db = new BDDContext()) + { + foreach (var item in runes) + { + EntityRunes rune = facto.RuneModelToEntity(item); + + int idImage = AddOneImage(); + rune.ImageId = idImage; + db.Add(rune); + } + db.SaveChanges(); + } + } + public void Init() { + //Image en même temps que champion,rune,Skin + + //Champion AddAllChampions(); + //Skin AddAllSkins(); + //Rune + AddAllRunes(); } } } diff --git a/Sources/EntityFramwork/BDD-APILOL.db b/Sources/EntityFramwork/BDD-APILOL.db index e5854ee..a7df7d8 100644 Binary files a/Sources/EntityFramwork/BDD-APILOL.db and b/Sources/EntityFramwork/BDD-APILOL.db differ diff --git a/Sources/EntityFramwork/BDDContext.cs b/Sources/EntityFramwork/BDDContext.cs index 853d1f7..a518f59 100644 --- a/Sources/EntityFramwork/BDDContext.cs +++ b/Sources/EntityFramwork/BDDContext.cs @@ -24,10 +24,6 @@ namespace EntityFramwork .HasMany(e => e.Skins) .WithOne(e => e.Champion) .HasForeignKey(e => e.ChampionForeignKey); - //Clé avec Images - modelBuilder.Entity().HasOne(n => n.Image) - .WithOne(c => c.Champion) - .HasForeignKey(c => c.Champion); // -------------------------------------------------------------------------------// //création de la table Skins modelBuilder.Entity().HasKey(m => m.Id); @@ -44,13 +40,32 @@ namespace EntityFramwork modelBuilder.Entity().HasKey(c => c.Id); modelBuilder.Entity().Property(c => c.Id) .ValueGeneratedOnAdd(); - - + //Relation Images et Champion + modelBuilder.Entity() + .HasOne(e => e.Champion) + .WithOne(z => z.Image) + .HasForeignKey(x => x.ImageId); + //Relation Images et Skins + modelBuilder.Entity() + .HasOne(e => e.Skin) + .WithOne(z => z.Image) + .HasForeignKey(x => x.ImageId); + //Relation Images et Rune + modelBuilder.Entity() + .HasOne(e => e.Rune) + .WithOne(z => z.Image) + .HasForeignKey(x => x.ImageId); + // -------------------------------------------------------------------------------// + //création de la table Runes + modelBuilder.Entity().HasKey(c => c.Id); + modelBuilder.Entity().Property(c => c.Id) + .ValueGeneratedOnAdd(); } public DbSet Champions { get; set; } public DbSet Skins { get; set; } public DbSet Images { get; set; } + public DbSet Runes { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/Sources/EntityFramwork/EntityChampions.cs b/Sources/EntityFramwork/EntityChampions.cs index 3c8285a..f1c9886 100644 --- a/Sources/EntityFramwork/EntityChampions.cs +++ b/Sources/EntityFramwork/EntityChampions.cs @@ -17,9 +17,13 @@ namespace DTO public string Bio { get; set; } public string Icon { get; set; } + public string Classe { get; set; } + // ----------------- Skin -----------------------// public List Skins { get; set; } + // ----------------- Image -----------------------// + public int ImageId { get; set; } public EntityLargeImage Image { get; set; } } diff --git a/Sources/EntityFramwork/EntityLargeImage.cs b/Sources/EntityFramwork/EntityLargeImage.cs index cf892b8..c77738a 100644 --- a/Sources/EntityFramwork/EntityLargeImage.cs +++ b/Sources/EntityFramwork/EntityLargeImage.cs @@ -13,6 +13,12 @@ namespace EntityFramwork public string Base64 { get; set; } + // --------- Champion ------------ // public EntityChampions Champion { get; set; } + + // --------- Skin ------------ // + public EntitySkins Skin { get; set; } + // --------- Rune ------------ // + public EntityRunes Rune { get; set; } } } diff --git a/Sources/EntityFramwork/EntityRunePage.cs b/Sources/EntityFramwork/EntityRunePage.cs new file mode 100644 index 0000000..78de44a --- /dev/null +++ b/Sources/EntityFramwork/EntityRunePage.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramwork +{ + public class EntityRunePage + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Sources/EntityFramwork/EntityRunes.cs b/Sources/EntityFramwork/EntityRunes.cs new file mode 100644 index 0000000..12a9633 --- /dev/null +++ b/Sources/EntityFramwork/EntityRunes.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramwork +{ + public class EntityRunes + { + public int Id { get; set; } + + public string Name { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + public string Family { get; set; } + + // --------- Images ---------- // + public int ImageId { get; set; } + public EntityLargeImage Image { get; set; } + } +} diff --git a/Sources/EntityFramwork/EntitySkill.cs b/Sources/EntityFramwork/EntitySkill.cs new file mode 100644 index 0000000..2d540c3 --- /dev/null +++ b/Sources/EntityFramwork/EntitySkill.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramwork +{ + public class EntitySkill + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public string Type { get; set; } + } +} diff --git a/Sources/EntityFramwork/EntitySkins.cs b/Sources/EntityFramwork/EntitySkins.cs index c72d4ff..4cf9ef6 100644 --- a/Sources/EntityFramwork/EntitySkins.cs +++ b/Sources/EntityFramwork/EntitySkins.cs @@ -19,9 +19,13 @@ namespace EntityFramwork public float Price { get; set; } + // ----------- Champion ----------- // public int ChampionForeignKey { get; set; } [ForeignKey("ChampionForeignKey")] public EntityChampions Champion { get; set; } + // ----------- Image ------------ // + public int ImageId { get; set; } + public EntityLargeImage Image { get; set; } } } diff --git a/Sources/EntityFramwork/Factories/Factories.cs b/Sources/EntityFramwork/Factories/Factories.cs index 557c405..e4a7aa9 100644 --- a/Sources/EntityFramwork/Factories/Factories.cs +++ b/Sources/EntityFramwork/Factories/Factories.cs @@ -12,6 +12,7 @@ namespace EntityFramwork.Factories entity.Name = champ.Name; entity.Bio = champ.Bio; entity.Icon = champ.Icon; + entity.Classe = champ.Class.ToString(); return entity; } @@ -24,7 +25,29 @@ namespace EntityFramwork.Factories entity.Icon = skin.Icon; entity.Description = skin.Description; entity.ChampionForeignKey = id; - //entity.Champion = ChampionModelToEntity(skin.Champion); + + return entity; + } + + public EntityRunes RuneModelToEntity(Rune rune) + { + EntityRunes entity = new EntityRunes(); + + entity.Name= rune.Name; + entity.Icon= rune.Icon; + entity.Description = rune.Description; + entity.Family = rune.Family.ToString(); + + return entity; + } + + public EntitySkill SkillModeleToEntity(Skill skill) + { + EntitySkill entity = new EntitySkill(); + + entity.Name = skill.Name; + entity.Description = skill.Description; + entity.Type = skill.Type.ToString(); return entity; } diff --git a/Sources/EntityFramwork/Migrations/20230208121743_test.Designer.cs b/Sources/EntityFramwork/Migrations/20230208121743_test.Designer.cs deleted file mode 100644 index 60e5442..0000000 --- a/Sources/EntityFramwork/Migrations/20230208121743_test.Designer.cs +++ /dev/null @@ -1,108 +0,0 @@ -// -using EntityFramwork; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramwork.Migrations -{ - [DbContext(typeof(BDDContext))] - [Migration("20230208121743_test")] - partial class test - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("DTO.EntityChampions", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("Champions"); - }); - - modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Base64") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("EntityFramwork.EntitySkins", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ChampionId") - .HasColumnType("INTEGER"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Price") - .HasColumnType("REAL"); - - b.HasKey("Id"); - - b.HasIndex("ChampionId"); - - b.ToTable("Skins"); - }); - - modelBuilder.Entity("EntityFramwork.EntitySkins", b => - { - b.HasOne("DTO.EntityChampions", "Champion") - .WithMany("Skins") - .HasForeignKey("ChampionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Champion"); - }); - - modelBuilder.Entity("DTO.EntityChampions", b => - { - b.Navigation("Skins"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs b/Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs deleted file mode 100644 index 70c622a..0000000 --- a/Sources/EntityFramwork/Migrations/20230208121840_test2.Designer.cs +++ /dev/null @@ -1,108 +0,0 @@ -// -using EntityFramwork; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramwork.Migrations -{ - [DbContext(typeof(BDDContext))] - [Migration("20230208121840_test2")] - partial class test2 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("DTO.EntityChampions", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("Champions"); - }); - - modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Base64") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Images"); - }); - - modelBuilder.Entity("EntityFramwork.EntitySkins", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("ChampionId") - .HasColumnType("INTEGER"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Price") - .HasColumnType("REAL"); - - b.HasKey("Id"); - - b.HasIndex("ChampionId"); - - b.ToTable("Skins"); - }); - - modelBuilder.Entity("EntityFramwork.EntitySkins", b => - { - b.HasOne("DTO.EntityChampions", "Champion") - .WithMany("Skins") - .HasForeignKey("ChampionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Champion"); - }); - - modelBuilder.Entity("DTO.EntityChampions", b => - { - b.Navigation("Skins"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramwork/Migrations/20230208121840_test2.cs b/Sources/EntityFramwork/Migrations/20230208121840_test2.cs deleted file mode 100644 index 845120e..0000000 --- a/Sources/EntityFramwork/Migrations/20230208121840_test2.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramwork.Migrations -{ - /// - public partial class test2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/Sources/EntityFramwork/Migrations/20230208135031_test3.cs b/Sources/EntityFramwork/Migrations/20230208135031_test3.cs deleted file mode 100644 index 7e99d9f..0000000 --- a/Sources/EntityFramwork/Migrations/20230208135031_test3.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramwork.Migrations -{ - /// - public partial class test3 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Skins_Champions_ChampionId", - table: "Skins"); - - migrationBuilder.RenameColumn( - name: "ChampionId", - table: "Skins", - newName: "ChampionForeignKey"); - - migrationBuilder.RenameIndex( - name: "IX_Skins_ChampionId", - table: "Skins", - newName: "IX_Skins_ChampionForeignKey"); - - migrationBuilder.AddForeignKey( - name: "FK_Skins_Champions_ChampionForeignKey", - table: "Skins", - column: "ChampionForeignKey", - principalTable: "Champions", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Skins_Champions_ChampionForeignKey", - table: "Skins"); - - migrationBuilder.RenameColumn( - name: "ChampionForeignKey", - table: "Skins", - newName: "ChampionId"); - - migrationBuilder.RenameIndex( - name: "IX_Skins_ChampionForeignKey", - table: "Skins", - newName: "IX_Skins_ChampionId"); - - migrationBuilder.AddForeignKey( - name: "FK_Skins_Champions_ChampionId", - table: "Skins", - column: "ChampionId", - principalTable: "Champions", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs b/Sources/EntityFramwork/Migrations/20230208221227_test.Designer.cs similarity index 52% rename from Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs rename to Sources/EntityFramwork/Migrations/20230208221227_test.Designer.cs index 3e06bb3..2a54103 100644 --- a/Sources/EntityFramwork/Migrations/20230208135031_test3.Designer.cs +++ b/Sources/EntityFramwork/Migrations/20230208221227_test.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFramwork.Migrations { [DbContext(typeof(BDDContext))] - [Migration("20230208135031_test3")] - partial class test3 + [Migration("20230208221227_test")] + partial class test { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -33,12 +33,18 @@ namespace EntityFramwork.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("ImageId") + .HasColumnType("INTEGER"); + b.Property("Name") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Id"); + b.HasIndex("ImageId") + .IsUnique(); + b.HasIndex("Name") .IsUnique(); @@ -47,7 +53,7 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); @@ -60,6 +66,35 @@ namespace EntityFramwork.Migrations b.ToTable("Images"); }); + modelBuilder.Entity("EntityFramwork.EntityRunes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ImageId") + .IsUnique(); + + b.ToTable("Runes"); + }); + modelBuilder.Entity("EntityFramwork.EntitySkins", b => { b.Property("Id") @@ -77,6 +112,9 @@ namespace EntityFramwork.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("ImageId") + .HasColumnType("INTEGER"); + b.Property("Price") .HasColumnType("REAL"); @@ -84,9 +122,34 @@ namespace EntityFramwork.Migrations b.HasIndex("ChampionForeignKey"); + b.HasIndex("ImageId") + .IsUnique(); + b.ToTable("Skins"); }); + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.HasOne("EntityFramwork.EntityLargeImage", "Image") + .WithOne("Champion") + .HasForeignKey("DTO.EntityChampions", "ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFramwork.EntityRunes", b => + { + b.HasOne("EntityFramwork.EntityLargeImage", "Image") + .WithOne("Rune") + .HasForeignKey("EntityFramwork.EntityRunes", "ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + }); + modelBuilder.Entity("EntityFramwork.EntitySkins", b => { b.HasOne("DTO.EntityChampions", "Champion") @@ -95,13 +158,33 @@ namespace EntityFramwork.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("EntityFramwork.EntityLargeImage", "Image") + .WithOne("Skin") + .HasForeignKey("EntityFramwork.EntitySkins", "ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.Navigation("Champion"); + + b.Navigation("Image"); }); modelBuilder.Entity("DTO.EntityChampions", b => { b.Navigation("Skins"); }); + + modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => + { + b.Navigation("Champion") + .IsRequired(); + + b.Navigation("Rune") + .IsRequired(); + + b.Navigation("Skin") + .IsRequired(); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/EntityFramwork/Migrations/20230208121743_test.cs b/Sources/EntityFramwork/Migrations/20230208221227_test.cs similarity index 50% rename from Sources/EntityFramwork/Migrations/20230208121743_test.cs rename to Sources/EntityFramwork/Migrations/20230208221227_test.cs index 2a337a8..0853c34 100644 --- a/Sources/EntityFramwork/Migrations/20230208121743_test.cs +++ b/Sources/EntityFramwork/Migrations/20230208221227_test.cs @@ -10,6 +10,19 @@ namespace EntityFramwork.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "Images", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Images", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Champions", columns: table => new @@ -18,24 +31,40 @@ namespace EntityFramwork.Migrations .Annotation("Sqlite:Autoincrement", true), Name = table.Column(type: "TEXT", nullable: false), Bio = table.Column(type: "TEXT", nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) + Icon = table.Column(type: "TEXT", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Champions", x => x.Id); + table.ForeignKey( + name: "FK_Champions_Images_ImageId", + column: x => x.ImageId, + principalTable: "Images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "Images", + name: "Runes", columns: table => new { - Id = table.Column(type: "INTEGER", nullable: false) + Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), - Base64 = table.Column(type: "TEXT", nullable: false) + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Images", x => x.Id); + table.PrimaryKey("PK_Runes", x => x.Id); + table.ForeignKey( + name: "FK_Runes_Images_ImageId", + column: x => x.ImageId, + principalTable: "Images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -47,19 +76,32 @@ namespace EntityFramwork.Migrations Description = table.Column(type: "TEXT", nullable: false), Icon = table.Column(type: "TEXT", nullable: false), Price = table.Column(type: "REAL", nullable: false), - ChampionId = table.Column(type: "INTEGER", nullable: false) + ChampionForeignKey = table.Column(type: "INTEGER", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Skins", x => x.Id); table.ForeignKey( - name: "FK_Skins_Champions_ChampionId", - column: x => x.ChampionId, + name: "FK_Skins_Champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, principalTable: "Champions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Skins_Images_ImageId", + column: x => x.ImageId, + principalTable: "Images", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Champions_ImageId", + table: "Champions", + column: "ImageId", + unique: true); + migrationBuilder.CreateIndex( name: "IX_Champions_Name", table: "Champions", @@ -67,22 +109,37 @@ namespace EntityFramwork.Migrations unique: true); migrationBuilder.CreateIndex( - name: "IX_Skins_ChampionId", + name: "IX_Runes_ImageId", + table: "Runes", + column: "ImageId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ChampionForeignKey", + table: "Skins", + column: "ChampionForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ImageId", table: "Skins", - column: "ChampionId"); + column: "ImageId", + unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( - name: "Images"); + name: "Runes"); migrationBuilder.DropTable( name: "Skins"); migrationBuilder.DropTable( name: "Champions"); + + migrationBuilder.DropTable( + name: "Images"); } } } diff --git a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs index 8fb37ab..c58c5bb 100644 --- a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs +++ b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs @@ -30,12 +30,18 @@ namespace EntityFramwork.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("ImageId") + .HasColumnType("INTEGER"); + b.Property("Name") .IsRequired() .HasColumnType("TEXT"); b.HasKey("Id"); + b.HasIndex("ImageId") + .IsUnique(); + b.HasIndex("Name") .IsUnique(); @@ -44,7 +50,7 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); @@ -57,6 +63,35 @@ namespace EntityFramwork.Migrations b.ToTable("Images"); }); + modelBuilder.Entity("EntityFramwork.EntityRunes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ImageId") + .IsUnique(); + + b.ToTable("Runes"); + }); + modelBuilder.Entity("EntityFramwork.EntitySkins", b => { b.Property("Id") @@ -74,6 +109,9 @@ namespace EntityFramwork.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("ImageId") + .HasColumnType("INTEGER"); + b.Property("Price") .HasColumnType("REAL"); @@ -81,9 +119,34 @@ namespace EntityFramwork.Migrations b.HasIndex("ChampionForeignKey"); + b.HasIndex("ImageId") + .IsUnique(); + b.ToTable("Skins"); }); + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.HasOne("EntityFramwork.EntityLargeImage", "Image") + .WithOne("Champion") + .HasForeignKey("DTO.EntityChampions", "ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFramwork.EntityRunes", b => + { + b.HasOne("EntityFramwork.EntityLargeImage", "Image") + .WithOne("Rune") + .HasForeignKey("EntityFramwork.EntityRunes", "ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + }); + modelBuilder.Entity("EntityFramwork.EntitySkins", b => { b.HasOne("DTO.EntityChampions", "Champion") @@ -92,13 +155,33 @@ namespace EntityFramwork.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("EntityFramwork.EntityLargeImage", "Image") + .WithOne("Skin") + .HasForeignKey("EntityFramwork.EntitySkins", "ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.Navigation("Champion"); + + b.Navigation("Image"); }); modelBuilder.Entity("DTO.EntityChampions", b => { b.Navigation("Skins"); }); + + modelBuilder.Entity("EntityFramwork.EntityLargeImage", b => + { + b.Navigation("Champion") + .IsRequired(); + + b.Navigation("Rune") + .IsRequired(); + + b.Navigation("Skin") + .IsRequired(); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/Model/Rune.cs b/Sources/Model/Rune.cs index 7b5047b..1b34dc8 100644 --- a/Sources/Model/Rune.cs +++ b/Sources/Model/Rune.cs @@ -39,7 +39,7 @@ namespace Model public LargeImage Image { get; set; } - public Rune(string name, RuneFamily family, string icon = "", string image = "", string description = "") + public Rune(string name, RuneFamily family, string icon = "Inconnu !", string image = "Inconnu !", string description = "Inconnu !") { Name = name; Family = family; diff --git a/Sources/Model/Skill.cs b/Sources/Model/Skill.cs index 0679ea6..fb40e95 100644 --- a/Sources/Model/Skill.cs +++ b/Sources/Model/Skill.cs @@ -35,7 +35,7 @@ namespace Model } private string description = ""; - public Skill(string name, SkillType type, string description = "") + public Skill(string name, SkillType type, string description = "Inconnu !") { Name = name; Type = type;