From ec99ef34cc718f55cceb51a8b58da4f964a76a69 Mon Sep 17 00:00:00 2001 From: pasquizzat Date: Wed, 8 Mar 2023 12:03:05 +0100 Subject: [PATCH] =?UTF-8?q?suppression=20ajout=C3=A9e=20:cool:,=20retrait?= =?UTF-8?q?=20de=20l'id=20dans=20l'entite,=20le=20nom=20est=20la=20nouvell?= =?UTF-8?q?e=20cl=C3=A9=20primaire,=20comme=20=C3=A7a=20on=20touche=20pas?= =?UTF-8?q?=20au=20model,=20vu=20qu'il=20ne=20vient=20pas=20de=20moi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BddTests/Program.cs | 24 +++++++++++++++--- Sources/BddTests/laBdd.db | Bin 20480 -> 20480 bytes Sources/Model2/ChampionEntity.cs | 5 ++-- ...30308101741_NouvelleMigration.Designer.cs} | 15 ++++------- ...cs => 20230308101741_NouvelleMigration.cs} | 6 ++--- .../ChampionContextModelSnapshot.cs | 11 +++----- Sources/Model2/laBdd.db | Bin 0 -> 20480 bytes Sources/TrucAuMilieu/ChampionConvert.cs | 2 +- Sources/TrucAuMilieu/DataBdd.Champions.cs | 12 ++++++--- 9 files changed, 43 insertions(+), 32 deletions(-) rename Sources/Model2/Migrations/{20230201083944_Migration1.Designer.cs => 20230308101741_NouvelleMigration.Designer.cs} (77%) rename Sources/Model2/Migrations/{20230201083944_Migration1.cs => 20230308101741_NouvelleMigration.cs} (76%) create mode 100644 Sources/Model2/laBdd.db diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs index fbd923e..1ff9cca 100644 --- a/Sources/BddTests/Program.cs +++ b/Sources/BddTests/Program.cs @@ -9,15 +9,33 @@ Console.WriteLine("allo?"); var dataMgr = new DataBdd(); + +//dataMgr.ChampionsMgr.AddItem(c1.EfToChamp()); //dataMgr.ChampionsMgr.AddItem(c2); -List list = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList(); -List list2 = dataMgr.ChampionsMgr.GetItemsByName("oe", 0, 30).Result.ToList(); + +/*List list1 = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList(); + +//List list2 = dataMgr.ChampionsMgr.GetItemsByName("oe", 0, 30).Result.ToList(); /*ChampionContext data = new ChampionContext(); data.Champs.ToList(); List l = data.listChampions();*/ +/* +foreach (var champion in list1) +{ + Console.WriteLine(champion.Name + ' ' + champion.Bio); +}*/ + + +if (dataMgr.ChampionsMgr.DeleteItem(c2).Result) + Console.WriteLine("joe est mort."); + +foreach (var champion in dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList()) { Console.WriteLine(champion.Name); } + + + + -foreach (var champion in list2) { Console.WriteLine(champion.Name); } diff --git a/Sources/BddTests/laBdd.db b/Sources/BddTests/laBdd.db index fc25159ba4a1cff77238020412f13517d20b0638..960b9917877a998822d190d6f38bcb3971db9f94 100644 GIT binary patch delta 393 zcmZozz}T>WQ6@OhC$l6~AuYcsH?c&)m_dMniHX5ML4kpRfoY?>|$ zU}S7yY+zw%U}$b)81I)~T9%rVlj@t9UX)mpnV)B_XP{@q1#~4N{~ZSYJDUX+F7cZv zGy8H9(#XsIf`OTT76boB{)7Cp_-6s_?BeHFWnqz5R!;^w3~0FVRljqo} zXaFtY}-wDKg~Ze+@M0JOlq{{=59=`CkJ~+Rtyu%Ph|bQ)0}5%rjyJ Rn#2J#hlz(-o)f0V5CBuoY}o(+ delta 567 zcmZozz}T>WQ6@OhC$l6~AuYcsH?c&)m_dMnk&(ecL4kpRfp?;evnVfvUc3}9{|^Qh z-gOLom-yH6G4QV2*l5KY6TreIuC2`&S(2EPlUiJu12iVSIJK}eH7^;R%jz8D>KNjx z5aQ_MZnO$5`lCi0BGCQ9Ew`Yoyf~Q}ItGjE^WJf+7eg((S z5PwfUpjp1Iejz%O4fv!c=ki%>zQkw3$a0r~|L$f%h12{K12}XQ8JX?HjSP&84U7y7 z4J?c;O-$l_Gt-L_OEUBG49)cn^o+QG9%STy%)tK`s*BHBhS{DIrzT#YdTzcJ2L2oT z8~8i;6ZkFo1^8a@9pIb6*T>hgSx_L2PlAJ+l|h)7H!DAtgA2w|<78!+e8gTwK#hZy zL0(xsIU_N*0O$(S$rtP;1k~731PvjAY}f=@u?ezZ6J*9F$b?Oh5mS&0R diff --git a/Sources/Model2/ChampionEntity.cs b/Sources/Model2/ChampionEntity.cs index 26e1e1c..8bc240b 100644 --- a/Sources/Model2/ChampionEntity.cs +++ b/Sources/Model2/ChampionEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,13 +9,13 @@ namespace LibEntityFramework { public class ChampionEntity { - public int Id { get; set; } + //j'ai retiré l'Id, je me suis dit que ça ferait plus de sens de ne pas toucher au model, car ce code n'est pas le mien. + [Key] public string Name { get; set; } public string Bio { get; set; } public string Icon { get; set; } public ChampionEntity(string name, string bio, string icon) { - Id = 0; Name = name; Bio = bio; Icon = icon; diff --git a/Sources/Model2/Migrations/20230201083944_Migration1.Designer.cs b/Sources/Model2/Migrations/20230308101741_NouvelleMigration.Designer.cs similarity index 77% rename from Sources/Model2/Migrations/20230201083944_Migration1.Designer.cs rename to Sources/Model2/Migrations/20230308101741_NouvelleMigration.Designer.cs index 4f52fc2..16eff4c 100644 --- a/Sources/Model2/Migrations/20230201083944_Migration1.Designer.cs +++ b/Sources/Model2/Migrations/20230308101741_NouvelleMigration.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace LibEntityFramework.Migrations { [DbContext(typeof(ChampionContext))] - [Migration("20230201083944_Migration1")] - partial class Migration1 + [Migration("20230308101741_NouvelleMigration")] + partial class NouvelleMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -21,9 +21,8 @@ namespace LibEntityFramework.Migrations modelBuilder.Entity("LibEntityFramework.ChampionEntity", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + b.Property("Name") + .HasColumnType("TEXT"); b.Property("Bio") .IsRequired() @@ -33,11 +32,7 @@ namespace LibEntityFramework.Migrations .IsRequired() .HasColumnType("TEXT"); - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); + b.HasKey("Name"); b.ToTable("Champs"); }); diff --git a/Sources/Model2/Migrations/20230201083944_Migration1.cs b/Sources/Model2/Migrations/20230308101741_NouvelleMigration.cs similarity index 76% rename from Sources/Model2/Migrations/20230201083944_Migration1.cs rename to Sources/Model2/Migrations/20230308101741_NouvelleMigration.cs index b4f2535..8e76646 100644 --- a/Sources/Model2/Migrations/20230201083944_Migration1.cs +++ b/Sources/Model2/Migrations/20230308101741_NouvelleMigration.cs @@ -5,7 +5,7 @@ namespace LibEntityFramework.Migrations { /// - public partial class Migration1 : Migration + public partial class NouvelleMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -14,15 +14,13 @@ namespace LibEntityFramework.Migrations name: "Champs", 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_Champs", x => x.Id); + table.PrimaryKey("PK_Champs", x => x.Name); }); } diff --git a/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs b/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs index 12e9911..a4bfb9c 100644 --- a/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs +++ b/Sources/Model2/Migrations/ChampionContextModelSnapshot.cs @@ -18,9 +18,8 @@ namespace LibEntityFramework.Migrations modelBuilder.Entity("LibEntityFramework.ChampionEntity", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); + b.Property("Name") + .HasColumnType("TEXT"); b.Property("Bio") .IsRequired() @@ -30,11 +29,7 @@ namespace LibEntityFramework.Migrations .IsRequired() .HasColumnType("TEXT"); - b.Property("Name") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); + b.HasKey("Name"); b.ToTable("Champs"); }); diff --git a/Sources/Model2/laBdd.db b/Sources/Model2/laBdd.db new file mode 100644 index 0000000000000000000000000000000000000000..ef2038119c608e19c4ffe4a11885b843d67d3c2b GIT binary patch literal 20480 zcmeI&zi!h&9Ki9jleQ4a4O#K|N`WmDV{x-OndDTL5f z+E8f~i+pjFQCsbg{dK##sQGt|@=sAT&c*h(@>k=0`^&nMDMtVS1Q0*~0R#|0009IL z_)h|-JB6)EwW^)%q`{kU*nSsG-p`inVteScJV$!1y^bTzWuYl|jgnMh_JT=hO3yj; zWUsH%%T7nO`@I8i*m8TGGza_ss>)#Kc3ZhBkplL%^WgH_a78D zD^IGLh^C|P)9k}o%~<_lp2ipX%Z_|&+2O|Np|(}AZSAaoF(}`6o^_+QNsvbIboM-& zrE&5(w^09k$hqhI7PxBD9c3;!3$do59G5{7kLJhet1y|Vi_J8v99(^~^4ebKklT-M z&T|`NwcP4zFHZ*tL4CQBvd5%0Gl!2m}y7009ILKmY**5I_I{1Q57}0{05t+y8nA zu=xJ3e)=a6KmY**5I_I{1Q0*~0R#|0;06mUzW+1-zri<{p&@_(0tg_000IagfB*sr IAfN<(0U_ new ChampionEntity(c.Name, c.Bio, c.Icon); - public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name); + public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name,ChampionClass.Tank,c.Icon,c.Icon,c.Bio); } } diff --git a/Sources/TrucAuMilieu/DataBdd.Champions.cs b/Sources/TrucAuMilieu/DataBdd.Champions.cs index 39a53dd..3bae1fc 100644 --- a/Sources/TrucAuMilieu/DataBdd.Champions.cs +++ b/Sources/TrucAuMilieu/DataBdd.Champions.cs @@ -14,7 +14,6 @@ namespace TrucAuMilieu public ChampionContext contextCh = new ChampionContext(); public class ChampionsManager : IChampionsManager { - private readonly DataBdd parent; public ChampionsManager(DataBdd parent) => this.parent = parent; @@ -27,10 +26,15 @@ namespace TrucAuMilieu return item; } - public Task DeleteItem(Champion? item) - //pas fait + public async Task DeleteItem(Champion? item) + //supprimer un champion? je crois? et renvoie true si il est supprimé? à tester { - throw new NotImplementedException(); + if (parent.contextCh.Champs.Remove(item.ChampToEf()).Entity==item.ChampToEf()) + { + await parent.contextCh.SaveChangesAsync(); + return true; + } + return false; } public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)