From 5ed4479c7db849153f0d09c9a46e793c6449ba82 Mon Sep 17 00:00:00 2001 From: Jolys Enzo Date: Sat, 4 Feb 2023 09:59:21 +0100 Subject: [PATCH] avancement --- Sources/Client/Program.cs | 18 +++--- Sources/EntityFramwork/BDD-APILOL.db | Bin 24576 -> 32768 bytes Sources/EntityFramwork/BDD-APILOL.db-shm | Bin 0 -> 32768 bytes Sources/EntityFramwork/BDD-APILOL.db-wal | Bin 0 -> 16512 bytes Sources/EntityFramwork/BDDContext.cs | 21 +++++++ Sources/EntityFramwork/EntityChampions.cs | 7 ++- Sources/EntityFramwork/EntitySkins.cs | 8 +-- Sources/EntityFramwork/Factories/Factories.cs | 19 +++++- .../20230201131800_migrationTest.cs | 54 ------------------ ...ner.cs => 20230204085418_TEST.Designer.cs} | 29 ++++++++-- .../Migrations/20230204085418_TEST.cs | 22 +++++++ .../Migrations/BDDContextModelSnapshot.cs | 25 +++++++- 12 files changed, 126 insertions(+), 77 deletions(-) create mode 100644 Sources/EntityFramwork/BDD-APILOL.db-shm create mode 100644 Sources/EntityFramwork/BDD-APILOL.db-wal delete mode 100644 Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs rename Sources/EntityFramwork/Migrations/{20230201131800_migrationTest.Designer.cs => 20230204085418_TEST.Designer.cs} (68%) create mode 100644 Sources/EntityFramwork/Migrations/20230204085418_TEST.cs diff --git a/Sources/Client/Program.cs b/Sources/Client/Program.cs index b799e30..5c8e5dc 100644 --- a/Sources/Client/Program.cs +++ b/Sources/Client/Program.cs @@ -8,19 +8,22 @@ using EntityFramwork.Factories; using Model; using StubLib; -/* + StubData tmp = new StubData(); var tmpListe = await tmp.ChampionsMgr.GetItemsByName("Akali", 0, 6); Champion champ = tmpListe.First(); Factories facto = new Factories(); -EntityChampions entity = facto.ModelToEntity(champ); +EntityChampions entity = facto.ChampionModelToEntity(champ); +List skins = new List(entity.Skins); + -using ( BDDContext context = new BDDContext()) +using ( BDDContext db = new BDDContext()) { - context.Add(entity); - context.SaveChanges(); + db.Add(entity); + db.SaveChanges(); } -*/ + +/* Console.WriteLine("Start"); Console.ReadLine(); @@ -40,4 +43,5 @@ DtoChampions champ2 = await client.GetChampion("toto"); Console.WriteLine(champ2.name); Console.WriteLine("End"); -Console.ReadLine(); \ No newline at end of file +Console.ReadLine(); +*/ \ No newline at end of file diff --git a/Sources/EntityFramwork/BDD-APILOL.db b/Sources/EntityFramwork/BDD-APILOL.db index 01f0722d3fe1a284be068bda2b1fb92693e659f8..3121d98a05c775b949469c47f75f9aa6958ec602 100644 GIT binary patch delta 972 zcmZoTz}V2hG(lRBje&uI1Bw}ew8%sqV`(-9y?7~JK1~KT?q~+SOZ;nj-tu1Oj^+#D zY~9$%&FR3W$($jsuFlxTTauWRlbV_qUy_p`B@OF(<&`^RaMpB}w5ajCS8szHd z>>8|qP@x1=?wO*bso?Jyq2S``;|lbJvtzKcql+sqmnNSk<34e5amKb#Z~%Zk4kkF9 zgMf02K!MX*3kjTNeol6fS|}f(mVL4TPv+1G27a_)*!+seiIGuzvM!%|JsT$|9WgM} zaIuTKiZeE9X6B`&R(M9BM-n33!NI@=O&*?pF0K&@O8C?(0V6^|39JhgHK;Mk4oN+l zn=kPhG4iqUdob`{<6p<$&Y#Nfu~|^SjNe|GmDyO_$iT?hz{tSFz{0@5$Rs|*H8{jv z&p^*efrZ%?A!%-EZeSjtpI20ppPQIh305(=UA`7*ZW06k9sZsC)A_6TlYr(1@LP&A z8#7`tmQ{w?79oyiB8wukJLBXYdD+c7^nC<482P_3@PFffvRTmJHoue%2P~67(i0Q2 aI0u-;wVBa?OMsCLsO&xe#0hX#04o5%_8WQt delta 202 zcmZo@U}`wPI6+#Fg@J*A4TxcYbE1y1I17Vbyc92=CIc&v7z5uW{yhGndU^7bqyTE2{gRlGmI@mIE diff --git a/Sources/EntityFramwork/BDD-APILOL.db-shm b/Sources/EntityFramwork/BDD-APILOL.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..2e0d47f4781296cc9a7b2b2ff7de105a9572ed0b GIT binary patch literal 32768 zcmeI)F$w}P5CFjBJVZOo`-G3M($fBF;cRXFfW7zyD_eX0iVsnfLk~N#lVcW^4M|wo zdB9e;X~j3KSvlIuZm35FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly IK;Rz*o_Bd8Hvj+t literal 0 HcmV?d00001 diff --git a/Sources/EntityFramwork/BDD-APILOL.db-wal b/Sources/EntityFramwork/BDD-APILOL.db-wal new file mode 100644 index 0000000000000000000000000000000000000000..cf1dcaee1d772f7ad0644ee037343a9ac9abe1c5 GIT binary patch literal 16512 zcmeI&JxIeq6bJA$*QQpG6I2xJ;0KBb$|aW&7blfkp@P`0NT?dLNE57G)IoI7%|XP? z$x&Ry!A-%*Sp>nUqnqF?UL$Q93GUkeqaE(OM@WC&-aT_qIgrLGJ(AQeRpUN&65Ul2 zpD#OePsbZ0A0j0;=JzZ2kGak+xlJS$Ix5j;dPNVZO=rac0Rad=00Izz00bZa0SG_< z0uX3gfuur=ZjEW2X-sDm2G_WiomtFsbDWK9y)nWYs*Gv6SM`d0Q8MWlO~YiS option) : base(option) { } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + //création de la table Champion + modelBuilder.Entity().HasKey(a => a.Id); + modelBuilder.Entity().Property(a => a.Id) + .ValueGeneratedOnAdd(); + + //création de la table Skins + modelBuilder.Entity().HasKey(m => m.Id); + modelBuilder.Entity().Property(m => m.Id) + .ValueGeneratedOnAdd(); + + //modelBuilder.Entity().Property("ChampionForeignKey"); + // Use the shadow property as a foreign key + modelBuilder.Entity() + .HasOne(m => m.Champion) + .WithMany(a => a.Skins) + .HasForeignKey("ChampionsForeignKey"); + } public DbSet Champions { get; set; } public DbSet Skins { get; set; } diff --git a/Sources/EntityFramwork/EntityChampions.cs b/Sources/EntityFramwork/EntityChampions.cs index 4708116..8b878ad 100644 --- a/Sources/EntityFramwork/EntityChampions.cs +++ b/Sources/EntityFramwork/EntityChampions.cs @@ -1,4 +1,5 @@ -using Model; +using EntityFramwork; +using Model; using System; using System.Collections.Generic; using System.Linq; @@ -9,7 +10,7 @@ namespace DTO { public class EntityChampions { - public long Id { get; set; } + public int Id { get; set; } public string Name { get; set; } @@ -17,7 +18,7 @@ namespace DTO public string Icon { get; set; } - //public List Skins { get; set; } + public List Skins { get; set; } } } diff --git a/Sources/EntityFramwork/EntitySkins.cs b/Sources/EntityFramwork/EntitySkins.cs index 17ac2a4..c956415 100644 --- a/Sources/EntityFramwork/EntitySkins.cs +++ b/Sources/EntityFramwork/EntitySkins.cs @@ -11,16 +11,14 @@ namespace EntityFramwork { public class EntitySkins { - public long Id { get; set; } + public int Id { get; set; } public string Description { get; set; } public string Icon { get; set; } public float Price { get; set; } + + public EntityChampions Champion { get; set; } - [ForeignKey("ChampionsForeignKey")] - public EntityChampions EntityChampion { get; set; } - - public long ChampionsForeignKey { get;set; } } } diff --git a/Sources/EntityFramwork/Factories/Factories.cs b/Sources/EntityFramwork/Factories/Factories.cs index 3c8bdf3..dc491c6 100644 --- a/Sources/EntityFramwork/Factories/Factories.cs +++ b/Sources/EntityFramwork/Factories/Factories.cs @@ -5,14 +5,29 @@ namespace EntityFramwork.Factories { public class Factories { - public EntityChampions ModelToEntity(Champion champ) + public EntityChampions ChampionModelToEntity(Champion champ,int sansSkin = 0) { EntityChampions entity = new EntityChampions(); entity.Name = champ.Name; entity.Bio = champ.Bio; entity.Icon = champ.Icon; - //entity.Skins = new List(champ.Skins); + if ( sansSkin == 0) + { + entity.Skins = champ.Skins.Select(Model => this.SkinsModelToEntity(Model)).ToList(); + } + + return entity; + } + + public EntitySkins SkinsModelToEntity(Skin skin) + { + EntitySkins entity= new EntitySkins(); + + entity.Price = skin.Price; + entity.Icon = skin.Icon; + entity.Description= skin.Description; + entity.Champion = ChampionModelToEntity(skin.Champion,1); return entity; } diff --git a/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs b/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs deleted file mode 100644 index 73050ce..0000000 --- a/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFramwork.Migrations -{ - /// - public partial class migrationTest : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champions", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .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) - }, - constraints: table => - { - table.PrimaryKey("PK_Champions", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Skins", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Description = table.Column(type: "TEXT", nullable: false), - Icon = table.Column(type: "TEXT", nullable: false), - Price = table.Column(type: "REAL", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Skins", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Champions"); - - migrationBuilder.DropTable( - name: "Skins"); - } - } -} diff --git a/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.Designer.cs b/Sources/EntityFramwork/Migrations/20230204085418_TEST.Designer.cs similarity index 68% rename from Sources/EntityFramwork/Migrations/20230201131800_migrationTest.Designer.cs rename to Sources/EntityFramwork/Migrations/20230204085418_TEST.Designer.cs index 364cbd8..ec97c73 100644 --- a/Sources/EntityFramwork/Migrations/20230201131800_migrationTest.Designer.cs +++ b/Sources/EntityFramwork/Migrations/20230204085418_TEST.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace EntityFramwork.Migrations { [DbContext(typeof(BDDContext))] - [Migration("20230201131800_migrationTest")] - partial class migrationTest + [Migration("20230204085418_TEST")] + partial class TEST { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -21,7 +21,7 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("DTO.EntityChampions", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); @@ -44,10 +44,13 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("EntityFramwork.EntitySkins", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("ChampionsForeignKey") + .HasColumnType("INTEGER"); + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); @@ -61,8 +64,26 @@ namespace EntityFramwork.Migrations b.HasKey("Id"); + b.HasIndex("ChampionsForeignKey"); + b.ToTable("Skins"); }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.HasOne("DTO.EntityChampions", "Champion") + .WithMany("Skins") + .HasForeignKey("ChampionsForeignKey") + .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/20230204085418_TEST.cs b/Sources/EntityFramwork/Migrations/20230204085418_TEST.cs new file mode 100644 index 0000000..148e9bf --- /dev/null +++ b/Sources/EntityFramwork/Migrations/20230204085418_TEST.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFramwork.Migrations +{ + /// + public partial class TEST : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs index 832c08b..dc6ff1d 100644 --- a/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs +++ b/Sources/EntityFramwork/Migrations/BDDContextModelSnapshot.cs @@ -18,7 +18,7 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("DTO.EntityChampions", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); @@ -41,10 +41,13 @@ namespace EntityFramwork.Migrations modelBuilder.Entity("EntityFramwork.EntitySkins", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("ChampionsForeignKey") + .HasColumnType("INTEGER"); + b.Property("Description") .IsRequired() .HasColumnType("TEXT"); @@ -58,8 +61,26 @@ namespace EntityFramwork.Migrations b.HasKey("Id"); + b.HasIndex("ChampionsForeignKey"); + b.ToTable("Skins"); }); + + modelBuilder.Entity("EntityFramwork.EntitySkins", b => + { + b.HasOne("DTO.EntityChampions", "Champion") + .WithMany("Skins") + .HasForeignKey("ChampionsForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("DTO.EntityChampions", b => + { + b.Navigation("Skins"); + }); #pragma warning restore 612, 618 } }