From f6a30752184734fd2d99a119e9a2f6e8631db5f7 Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Thu, 23 Mar 2023 23:11:59 +0100 Subject: [PATCH] Ajout put et delete --- .../Controllers/ChampionsController.cs | 37 ++++++++++-------- Sources/API_LoL/champion.db | Bin 45056 -> 45056 bytes Sources/API_LoL/champion.db-shm | Bin 32768 -> 32768 bytes Sources/API_LoL/champion.db-wal | Bin 0 -> 8272 bytes Sources/DTO/ChampionDTO.cs | 4 +- .../Manager/EFDataManager.Champions.cs | 32 +++++++++++++-- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index b2d58bd..86f7a94 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -103,22 +103,22 @@ namespace API_LoL.Controllers else { return NoContent(); } } - [HttpGet("name/skills")] - public async Task GetSkillsByName(String name) - { - if (string.IsNullOrEmpty(name)) return BadRequest(); - var list = await ChampionsManager.GetItemsByName(name, 0, 1); - if (list.Count() == 1) - { - var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); - if (skins.Count() != 0) - { - return Ok(skins.Select(skin => skin?.ToDTO())); - } - else { return NoContent(); } - } - else { return NoContent(); } - } + //[HttpGet("name/skills")] + //public async Task GetSkillsByName(String name) + //{ + // if (string.IsNullOrEmpty(name)) return BadRequest(); + // var list = await ChampionsManager.GetItemsByName(name, 0, 1); + // if (list.Count() == 1) + // { + // var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); + // if (skins.Count() != 0) + // { + // return Ok(skins.Select(skin => skin?.ToDTO())); + // } + // else { return NoContent(); } + // } + // else { return NoContent(); } + //} @@ -132,6 +132,11 @@ namespace API_LoL.Controllers } else { + var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1); + if(champ.FirstOrDefault().Name == champion.Name) + { + return Conflict(champion); + } await ChampionsManager.AddItem(champion.ToChampion()); return CreatedAtAction("Post",champion); diff --git a/Sources/API_LoL/champion.db b/Sources/API_LoL/champion.db index bea5ebdc870b51ff37a7cbd336d99b26a24da2d7..cfdeed20a24e3204770fcb3599b2dbddcd974542 100644 GIT binary patch delta 104 zcmZp8z|`=7X# zz!<~wB1=05ldF=V9>;9kX8UtOG~G67r+HyBT@%Ki4)d1nL|in=gKeiOEN>*OEY(5P zV~ebN DeleteItem(Champion? item) + public async Task DeleteItem(Champion? item) { - throw new NotImplementedException(); + using (var context = new LoLDBContextWithStub()) + { + var champ = context.Champions.Select(c => c == item.ToEntity()); + + if(champ.Count()<1) + { + return false; + } + context.Champions.Remove(item.ToEntity()); + context.SaveChanges(); + return true; + + } } public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) @@ -150,9 +164,19 @@ namespace EntityFramework.Manager throw new NotImplementedException(); } - public Task UpdateItem(Champion? oldItem, Champion? newItem) + public async Task UpdateItem(Champion? oldItem, Champion? newItem) { - throw new NotImplementedException(); + using(var context = new LoLDBContextWithStub()) + { + if (oldItem != null && newItem != null) + { + var champ = context.Champions.Where(c => c == oldItem.ToEntity()).First(); + champ = newItem.ToEntity(); + context.SaveChanges(); + return newItem; + } + else { throw new Exception(); } + } } } }