From f8b4b0cf56fff4fec375cf0a3e0a8590ed3a8ce7 Mon Sep 17 00:00:00 2001 From: pasquizzat Date: Thu, 9 Feb 2023 09:58:01 +0100 Subject: [PATCH] EF : bug dans le truc pour sauvegarder, l'implementation de IChampionManager est tres chiante --- Sources/BddTests/BddTests.csproj | 2 +- Sources/BddTests/Program.cs | 26 +++-- Sources/BddTests/laBdd.db | Bin 20480 -> 20480 bytes Sources/Model2/ChampionContext.cs | 7 +- Sources/TrucAuMilieu/ChampionConvert.cs | 16 +++ Sources/TrucAuMilieu/Data.cs | 18 ---- Sources/TrucAuMilieu/DataBdd.Champions.cs | 114 ++++++++++++++++++++++ Sources/TrucAuMilieu/DataBdd.cs | 25 +++++ Sources/TrucAuMilieu/toEntity.cs | 13 --- 9 files changed, 174 insertions(+), 47 deletions(-) create mode 100644 Sources/TrucAuMilieu/ChampionConvert.cs delete mode 100644 Sources/TrucAuMilieu/Data.cs create mode 100644 Sources/TrucAuMilieu/DataBdd.Champions.cs create mode 100644 Sources/TrucAuMilieu/DataBdd.cs delete mode 100644 Sources/TrucAuMilieu/toEntity.cs diff --git a/Sources/BddTests/BddTests.csproj b/Sources/BddTests/BddTests.csproj index da8ca3d..e2c3db3 100644 --- a/Sources/BddTests/BddTests.csproj +++ b/Sources/BddTests/BddTests.csproj @@ -24,7 +24,7 @@ - + diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs index 6170634..a0cc9ae 100644 --- a/Sources/BddTests/Program.cs +++ b/Sources/BddTests/Program.cs @@ -1,26 +1,24 @@ using LibEntityFramework; +using Model; using TrucAuMilieu; -ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg"); +ChampionEntity c1 = new ChampionEntity("champion1", "il est beau", "imagepng.jpeg"); +Champion c2 = new Champion("joe"); Console.WriteLine("allo?"); -using (var context = new ChampionContext()) -{ - context.Add(c1); - context.SaveChanges(); +var dataMgr = new DataBdd(); - Console.WriteLine("champion ajouté"); +await dataMgr.ChampionsMgr.AddItem(c2); +Console.WriteLine("champion ajouté"); - List l = context.Champs.ToList(); +List list = dataMgr.ChampionsMgr.GetItems(0, 5).Result.ToList(); - foreach (var champion in l) { Console.WriteLine(champion.Name); } -} -using (var data = new Data()) -{ - List l = data.listChampions()); +/* +ChampionContext data = new ChampionContext(); - foreach (var champion in l) { Console.WriteLine(champion.Name); } +data.Champs.ToList(); +List l = data.listChampions();*/ -} \ No newline at end of file +foreach (var champion in list) { Console.WriteLine(champion.Name); } diff --git a/Sources/BddTests/laBdd.db b/Sources/BddTests/laBdd.db index 3e282a678ad461e43d8bef9fd7e20111f45e88cd..fd2359e406aa5dd5643f4b97fce5da13337527a1 100644 GIT binary patch delta 129 zcmZozz}T>Wae_1>_e2?IM(&LXOZ3G!`DQTi-{9ZC-@%{2Z^19X_k!;L-;B+I0(E=> zYMiVL^2+MT8Hu?CnfZA}lMmQS@^hewnS#U^*(cw!S7TCRgHWsxiUmS3gQ(3L?EM88 FIRQQqBWae_1>%S0JxMwX2UOY}LI_%|@{-{9Y{Sx{gJ|K<(${sN3l0QYJO#sB~S diff --git a/Sources/Model2/ChampionContext.cs b/Sources/Model2/ChampionContext.cs index 39a4cab..14a1003 100644 --- a/Sources/Model2/ChampionContext.cs +++ b/Sources/Model2/ChampionContext.cs @@ -11,6 +11,11 @@ namespace LibEntityFramework public DbSet Champs { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlite("DataSource=laBdd.db"); + { + if (!options.IsConfigured) + { + options.UseSqlite("DataSource=laBdd.db"); + } + } } } diff --git a/Sources/TrucAuMilieu/ChampionConvert.cs b/Sources/TrucAuMilieu/ChampionConvert.cs new file mode 100644 index 0000000..b874100 --- /dev/null +++ b/Sources/TrucAuMilieu/ChampionConvert.cs @@ -0,0 +1,16 @@ +using LibEntityFramework; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrucAuMilieu +{ + public static class ChampionConvert + { + public static ChampionEntity ChampToEf(this Champion c) => new ChampionEntity(c.Name, c.Bio, c.Icon); + public static Champion EfToChamp(this ChampionEntity c) => new Champion(c.Name); + } +} diff --git a/Sources/TrucAuMilieu/Data.cs b/Sources/TrucAuMilieu/Data.cs deleted file mode 100644 index 96782b5..0000000 --- a/Sources/TrucAuMilieu/Data.cs +++ /dev/null @@ -1,18 +0,0 @@ -using LibEntityFramework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TrucAuMilieu -{ - public class Data - { - ChampionContext context = new ChampionContext(); - List listChampions() - { - return context.Champs.ToList(); - } - } -} diff --git a/Sources/TrucAuMilieu/DataBdd.Champions.cs b/Sources/TrucAuMilieu/DataBdd.Champions.cs new file mode 100644 index 0000000..dfdbefc --- /dev/null +++ b/Sources/TrucAuMilieu/DataBdd.Champions.cs @@ -0,0 +1,114 @@ +using LibEntityFramework; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrucAuMilieu +{ + public partial class DataBdd + { + public ChampionContext contextCh = new ChampionContext(); + public class ChampionsManager : IChampionsManager + { + private readonly DataBdd parent; + public ChampionsManager(DataBdd parent) + => this.parent = parent; + public async Task AddItem (Champion? item) + {// ya comme une erreur le truc n'est pas save dans la bdd :( + await parent.contextCh.AddAsync(item.ChampToEf); + await parent.contextCh.SaveChangesAsync(); + return item; //ou elle est lerreur je vais menerve elle est ou lerreur >:( + } + + public Task DeleteItem(Champion? item) + { + throw new NotImplementedException(); + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)/* + => parent.contextCh..GetItemsWithFilterAndOrdering( + c => true, + index, count, + orderingPropertyName, descending);*/ + {// hihihi les arguments servent à rien pour l'instant y'a zero arguments utilises oupsi :3 + List lch = parent.contextCh.Champs.Take(count).Skip(index).ToList(); + List items = new List(); + foreach (var c in lch) { items.Add(c.EfToChamp()); } + return items; + } + + public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByCharacteristic(string charName) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByClass(ChampionClass championClass) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByName(string substring) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByRunePage(RunePage? runePage) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsBySkill(Skill? skill) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsBySkill(string skill) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Champion? oldItem, Champion? newItem) + { + throw new NotImplementedException(); + } + } + } +} diff --git a/Sources/TrucAuMilieu/DataBdd.cs b/Sources/TrucAuMilieu/DataBdd.cs new file mode 100644 index 0000000..4a31b59 --- /dev/null +++ b/Sources/TrucAuMilieu/DataBdd.cs @@ -0,0 +1,25 @@ +using LibEntityFramework; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrucAuMilieu +{ + public partial class DataBdd : IDataManager + { + public DataBdd() + { + ChampionsMgr = new ChampionsManager(this); + } + public IChampionsManager ChampionsMgr { get; } + + public ISkinsManager? SkinsMgr { get; } + + public IRunesManager? RunesMgr { get; } + + public IRunePagesManager? RunePagesMgr { get; } + } +} diff --git a/Sources/TrucAuMilieu/toEntity.cs b/Sources/TrucAuMilieu/toEntity.cs deleted file mode 100644 index b447545..0000000 --- a/Sources/TrucAuMilieu/toEntity.cs +++ /dev/null @@ -1,13 +0,0 @@ -using LibEntityFramework; -using Model; - -namespace TrucAuMilieu -{ - static class toEntity - { - public static ChampionEntity ToEntity(this Champion c) - { - return new ChampionEntity(c.Name, c.Bio, c.Icon); - } - } -} \ No newline at end of file