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 bea5ebd..cfdeed2 100644 Binary files a/Sources/API_LoL/champion.db and b/Sources/API_LoL/champion.db differ diff --git a/Sources/API_LoL/champion.db-shm b/Sources/API_LoL/champion.db-shm index fe9ac28..bc92bf7 100644 Binary files a/Sources/API_LoL/champion.db-shm and b/Sources/API_LoL/champion.db-shm differ diff --git a/Sources/API_LoL/champion.db-wal b/Sources/API_LoL/champion.db-wal index e69de29..8456db7 100644 Binary files a/Sources/API_LoL/champion.db-wal and b/Sources/API_LoL/champion.db-wal differ diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs index e90b862..23478dd 100644 --- a/Sources/DTO/ChampionDTO.cs +++ b/Sources/DTO/ChampionDTO.cs @@ -5,12 +5,12 @@ namespace DTO { public class ChampionDTO { - public ChampionDTO(string name, string bio, string icon, string championClassDTO, string image) + public ChampionDTO(string name, string bio, string icon, string Class, string image) { Name = name; Bio = bio; Icon = icon; - Class = championClassDTO; + this.Class = Class; Image = image; } public string Name { get; set; } diff --git a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs index e784096..cef096a 100644 --- a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs +++ b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs @@ -26,7 +26,9 @@ namespace EntityFramework.Manager { if (item != null) { + context.Add(item.ToEntity()); + context.SaveChanges(); return item; } else @@ -36,9 +38,21 @@ namespace EntityFramework.Manager } } - public Task 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(); } + } } } }