From 2effc22f3006918ce693adfe1a7f8800f59585b5 Mon Sep 17 00:00:00 2001 From: pasquizzat Date: Wed, 1 Mar 2023 09:53:42 +0100 Subject: [PATCH] y'a des requetes crud en plus, le getbyname, il permet la suppression :wastebasket: --- Sources/BddTests/Program.cs | 4 +-- Sources/TrucAuMilieu/DataBdd.Champions.cs | 40 +++++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs index afd7f7a..fbd923e 100644 --- a/Sources/BddTests/Program.cs +++ b/Sources/BddTests/Program.cs @@ -12,7 +12,7 @@ var dataMgr = new DataBdd(); //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(); /*ChampionContext data = new ChampionContext(); @@ -20,4 +20,4 @@ List list = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetN data.Champs.ToList(); List l = data.listChampions();*/ -foreach (var champion in list) { Console.WriteLine(champion.Name); } +foreach (var champion in list2) { Console.WriteLine(champion.Name); } diff --git a/Sources/TrucAuMilieu/DataBdd.Champions.cs b/Sources/TrucAuMilieu/DataBdd.Champions.cs index 02f087c..39a53dd 100644 --- a/Sources/TrucAuMilieu/DataBdd.Champions.cs +++ b/Sources/TrucAuMilieu/DataBdd.Champions.cs @@ -19,6 +19,7 @@ namespace TrucAuMilieu public ChampionsManager(DataBdd parent) => this.parent = parent; public async Task AddItem (Champion? item) + //ajoute un champion à la base { await parent.contextCh.AddAsync(item.ChampToEf()); await parent.contextCh.SaveChangesAsync(); @@ -27,11 +28,13 @@ namespace TrucAuMilieu } public Task DeleteItem(Champion? item) + //pas fait { throw new NotImplementedException(); } public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + //requete sur les champions avec des arguments (genre la pagination est possible, et y'a le descending et tout) { if (orderingPropertyName != null) { @@ -43,7 +46,6 @@ namespace TrucAuMilieu { var pap = await Task.FromResult(parent.contextCh.Champs.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); return pap; - //ya une petite betise ça marche pas trop menfin bref c'est a corriger } } else @@ -54,68 +56,100 @@ namespace TrucAuMilieu } public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + //pas fait { throw new NotImplementedException(); } public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) + //pas fait { throw new NotImplementedException(); } - public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + //requete des champions dont le nom contient substring { - throw new NotImplementedException(); + var i = from c in parent.contextCh.Champs where c.Name.Contains(substring) select c; + if (orderingPropertyName != null) + { + if (descending) + { + return await Task.FromResult(i.OrderByDescending(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + } + else + { + var pap = await Task.FromResult(i.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + return pap; + } + } + else + { + var pap2 = await Task.FromResult(i.Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + return pap2; + } + } public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) + //pas fait { throw new NotImplementedException(); } public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + //pas fait { throw new NotImplementedException(); } public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + //pas fait { throw new NotImplementedException(); } public Task GetNbItems() => Task.FromResult(parent.contextCh.Champs.Count()); + //donne le nombre de champions dans la base public Task GetNbItemsByCharacteristic(string charName) + //pas fait { throw new NotImplementedException(); } public Task GetNbItemsByClass(ChampionClass championClass) + //pas fait { throw new NotImplementedException(); } public Task GetNbItemsByName(string substring) + //pas fait { throw new NotImplementedException(); } public Task GetNbItemsByRunePage(RunePage? runePage) + //pas fait { throw new NotImplementedException(); } public Task GetNbItemsBySkill(Skill? skill) + //pas fait { throw new NotImplementedException(); } public Task GetNbItemsBySkill(string skill) + //pas fait { throw new NotImplementedException(); } public Task UpdateItem(Champion? oldItem, Champion? newItem) + //met à jour un champion (pas fait) { throw new NotImplementedException(); }