From 0b1090aab5caff008ed63f1dacf72b22516b676a Mon Sep 17 00:00:00 2001 From: "arthur.valin" Date: Wed, 1 Mar 2023 17:17:15 +0100 Subject: [PATCH] Starting DbDataManager implementation --- .vs/League-of-Legends_Project3/v17/.wsuo | Bin 18944 -> 18944 bytes .../API_LoL_Project/API_LoL_Project.csproj | 1 + .../Controllers/ChampionsController.cs | 8 +- .../API_LoL_Project/Mapper/ChampionMapper.cs | 30 ++++-- .../API_LoL_Project/Mapper/RuneMapper.cs | 27 +++++ .../API_LoL_Project/Mapper/RunePageMapper.cs | 19 ++++ .../API_LoL_Project/Mapper/SkinMapper.cs | 23 ++++ .../Sources/Business/Business.csproj | 2 + .../Sources/Business/DbData.Champions.cs | 100 +++++++++++------- .../Sources/Business/DbData.RunePages.cs | 65 +++++++----- .../Sources/Business/DbData.Runes.cs | 55 +++++----- .../Sources/Business/DbData.Skins.cs | 56 +++++----- .../Sources/Business/DbData.cs | 9 +- .../Sources/Entities/ChampionEntity.cs | 9 +- .../Sources/Entities/CharacteristicEntity.cs | 28 +++++ .../Sources/Entities/Entities.Champions.db | Bin 81920 -> 110592 bytes .../Entities/Entities.Champions.db-shm | Bin 32768 -> 32768 bytes .../Sources/Entities/Entities.csproj | 2 +- .../{ChampionDbContext.cs => LolDbContext.cs} | 18 +++- .../Sources/Entities/Program.cs | 2 +- .../Sources/Entities/RunePageEntity.cs | 2 +- 21 files changed, 319 insertions(+), 137 deletions(-) create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs create mode 100644 EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs rename EntityFramework_LoL/Sources/Entities/{ChampionDbContext.cs => LolDbContext.cs} (86%) diff --git a/.vs/League-of-Legends_Project3/v17/.wsuo b/.vs/League-of-Legends_Project3/v17/.wsuo index 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DA}ydt|O{)jBQIp@Htd4^ka3Wnvmu2Hh;1;ftm QJ0-j1SoxaCF3L&y55|d1a{vGU diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj index d0782fd..f2b6d61 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj +++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj @@ -12,6 +12,7 @@ + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs index 98c9a35..49c3f0e 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs @@ -21,7 +21,7 @@ namespace API_LoL_Project.Controllers { var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); - return Ok(new { result = champions.Select(c => c.toDTO())}); + return Ok(new { result = champions.Select(c => c.ToDTO())}); } @@ -32,14 +32,14 @@ namespace API_LoL_Project.Controllers var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); - return Ok(new { result = champion.First().toDTO() }); + return Ok(new { result = champion.First().ToDTO() }); } // POST api/ [HttpPost] public async Task Post([FromBody] ChampionDTO value) { - await dataManager.AddItem(value.toModel()); + await dataManager.AddItem(value.ToModel()); return Ok(); } @@ -50,7 +50,7 @@ namespace API_LoL_Project.Controllers { var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); - await dataManager.UpdateItem(champion.First(), value.toModel()); + await dataManager.UpdateItem(champion.First(), value.ToModel()); return Ok(); } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs index 6d16cac..b2a7dcd 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs @@ -1,21 +1,39 @@ using DTO; +using Entities; using Model; namespace API_LoL_Project.Mapper { - public static class ChampionMapper - { - public static ChampionDTO toDTO(this Champion item) + public static class ChampionMapper { + + public static ChampionDTO ToDTO(this Champion item) { - return new ChampionDTO() { + return new() { Name = item.Name, Bio = item.Bio }; } - public static Champion toModel(this ChampionDTO dto) + public static ChampionEntity ToEntity(this Champion item) { - return new Champion(dto.Name); + return new() + { + Name = item.Name, + Bio = item.Bio, + Icon = item.Icon, + Class = item.Class, + Image = new() { Base64 = item.Image.Base64 }, + }; + } + + public static Champion ToModel(this ChampionDTO dto) + { + return new(dto.Name); + } + + public static Champion ToModel(this ChampionEntity entity) + { + return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio); } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs new file mode 100644 index 0000000..3b2b752 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs @@ -0,0 +1,27 @@ +namespace API_LoL_Project.Mapper +{ + using DTO; + using Entities; + using Model; + + namespace API_LoL_Project.Mapper + { + public static class RuneMapper + { + public static RuneEntity ToEntity(this Rune item) + { + throw new NotImplementedException(); + } + + + public static Rune ToModel(this RuneEntity entity) + { + throw new NotImplementedException(); + + } + + } + } +} + +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs new file mode 100644 index 0000000..611ed6e --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs @@ -0,0 +1,19 @@ +using Entities; +using Model; + +namespace API_LoL_Project.Mapper +{ + public static class RunePageMapper + { + public static RunePageEntity ToEntity(this RunePage item) + { + throw new NotImplementedException(); + } + + public static RunePage ToModel(this RunePageEntity entity) + { + throw new NotImplementedException(); + + } + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs new file mode 100644 index 0000000..ad5a96b --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs @@ -0,0 +1,23 @@ +using DTO; +using Entities; +using Model; + +namespace API_LoL_Project.Mapper +{ + public static class SkinMapper + { + public static SkinEntity ToEntity(this Skin item) + { + throw new NotImplementedException(); + } + + + public static Skin ToModel(this SkinEntity entity) + { + throw new NotImplementedException(); + + } + + } +} +} diff --git a/EntityFramework_LoL/Sources/Business/Business.csproj b/EntityFramework_LoL/Sources/Business/Business.csproj index ac52241..ac7fce7 100644 --- a/EntityFramework_LoL/Sources/Business/Business.csproj +++ b/EntityFramework_LoL/Sources/Business/Business.csproj @@ -7,6 +7,8 @@ + + diff --git a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs index a7bdf5e..03d2ff8 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs @@ -1,10 +1,7 @@ -using Model; +using API_LoL_Project.Mapper; +using Model; using Shared; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Data.SqlTypes; namespace Business { @@ -17,89 +14,112 @@ namespace Business public ChampionsManager(DbData parent) => this.parent = parent; - public Task AddItem(Champion? item) + public async Task AddItem(Champion? item) { - throw new NotImplementedException(); + await parent.DbContext.champions.AddAsync(item.ToEntity()); + return item; } - public Task DeleteItem(Champion? item) + public async Task DeleteItem(Champion? item) { - throw new NotImplementedException(); + parent.DbContext.champions.Remove(item.ToEntity()); + return true; } - public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.champions.Select(c =>c.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.Characteristics.Any(ch => ch.Name.Equals(charName))) + .Select(c => c.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.Class.Equals(championClass)) + .Select(c => c.ToModel()) + .Skip(index * count).Take(count); } - 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) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.Name.Contains(substring)) + .Select(c => c.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity()) + .Select(c => c.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => skill!=null && c.Skills.Any(s => s.Name.Equals(skill.Name))) + .Select(c => c.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill))) + .Select(c => c.ToModel()) + .Skip(index * count).Take(count); } - public Task GetNbItems() + public async Task GetNbItems() { - throw new NotImplementedException(); + return parent.DbContext.champions.Count(); } - public Task GetNbItemsByCharacteristic(string charName) + public async Task GetNbItemsByCharacteristic(string charName) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.Characteristics.Any(ch => ch.Name.Equals(charName))).Count(); } - public Task GetNbItemsByClass(ChampionClass championClass) + public async Task GetNbItemsByClass(ChampionClass championClass) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.Class.Equals(championClass)) + .Count(); } - public Task GetNbItemsByName(string substring) + public async Task GetNbItemsByName(string substring) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.Name.Contains(substring)) + .Count(); } - public Task GetNbItemsByRunePage(RunePage? runePage) + public async Task GetNbItemsByRunePage(RunePage? runePage) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity()))).Count(); + } - public Task GetNbItemsBySkill(Skill? skill) + public async Task GetNbItemsBySkill(Skill? skill) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name))) + .Count(); } - public Task GetNbItemsBySkill(string skill) + public async Task GetNbItemsBySkill(string skill) { - throw new NotImplementedException(); + return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill))) + .Count(); } - public Task UpdateItem(Champion? oldItem, Champion? newItem) + public async Task UpdateItem(Champion? oldItem, Champion? newItem) { - throw new NotImplementedException(); + parent.DbContext.champions.Remove(oldItem.ToEntity()); + parent.DbContext.champions.Add(newItem.ToEntity()); + return newItem; } } } +} diff --git a/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs b/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs index bf1aa5d..b7ea7fc 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs @@ -1,9 +1,5 @@ -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using API_LoL_Project.Mapper; +using Model; namespace Business { @@ -16,59 +12,72 @@ namespace Business public RunePagesManager(DbData parent) => this.parent = parent; - public Task AddItem(RunePage? item) + public async Task AddItem(RunePage? item) { - throw new NotImplementedException(); + await parent.DbContext.runepages.AddAsync(item.ToEntity()); + return item; } - public Task DeleteItem(RunePage? item) + public async Task DeleteItem(RunePage? item) { - throw new NotImplementedException(); + parent.DbContext.runepages.Remove(item.ToEntity()); + return true; } - public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Select(rp => rp.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Where(rp => rp.champions.Any(c => c.Name.Equals(champion.Name))) + .Select(rp => rp.ToModel()) + .Skip(index * count).Take(count); } - 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) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Where(rp => rp.Name.Contains(substring)) + .Select(rp => rp.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByRune(Model.Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByRune(Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Where(rp => rp.runes.Any(r => r.Name.Equals(rune.Name))) + .Select(rp => rp.ToModel()) + .Skip(index * count).Take(count); } - public Task GetNbItems() + public async Task GetNbItems() { - throw new NotImplementedException(); + return parent.DbContext.runepages.Count(); + } - public Task GetNbItemsByChampion(Champion? champion) + public async Task GetNbItemsByChampion(Champion? champion) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Where(rp => rp.champions.Any(c => c.Name.Equals(champion.Name))).Count(); + } - public Task GetNbItemsByName(string substring) + public async Task GetNbItemsByName(string substring) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Where(rp => rp.Name.Contains(substring)).Count(); } - public Task GetNbItemsByRune(Model.Rune? rune) + public async Task GetNbItemsByRune(Model.Rune? rune) { - throw new NotImplementedException(); + return parent.DbContext.runepages.Where(rp => rp.runes.Any(r => r.Name.Equals(rune.Name))).Count(); } - public Task UpdateItem(RunePage? oldItem, RunePage? newItem) + public async Task UpdateItem(RunePage? oldItem, RunePage? newItem) { - throw new NotImplementedException(); + parent.DbContext.runepages.Remove(oldItem.ToEntity()); + parent.DbContext.runepages.Add(newItem.ToEntity()); + return newItem; } } } diff --git a/EntityFramework_LoL/Sources/Business/DbData.Runes.cs b/EntityFramework_LoL/Sources/Business/DbData.Runes.cs index e0e796c..bcd964f 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Runes.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Runes.cs @@ -1,10 +1,7 @@ -using Model; +using API_LoL_Project.Mapper; +using API_LoL_Project.Mapper.API_LoL_Project.Mapper; +using Model; using Shared; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Business { @@ -16,49 +13,59 @@ namespace Business public RunesManager(DbData parent) => this.parent = parent; - public Task AddItem(Model.Rune? item) + public async Task AddItem(Rune? item) { - throw new NotImplementedException(); + await parent.DbContext.runes.AddAsync(item.ToEntity()); + return item; } - public Task DeleteItem(Model.Rune? item) + public async Task DeleteItem(Rune? item) { - throw new NotImplementedException(); + parent.DbContext.runes.Remove(item.ToEntity()); + return true; } - public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.runes + .Select(r => r.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.runes.Where(r => r.RuneFamily.Equals(family)) + .Select(r => r.ToModel()) + .Skip(index * count).Take(count); } - 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) { - throw new NotImplementedException(); + return parent.DbContext.runes.Where(r => r.Name.Contains(substring)) + .Select(r => r.ToModel()) + .Skip(index * count).Take(count); } - public Task GetNbItems() + public async Task GetNbItems() { - throw new NotImplementedException(); + return parent.DbContext.runes.Count(); } - public Task GetNbItemsByFamily(RuneFamily family) + public async Task GetNbItemsByFamily(RuneFamily family) { - throw new NotImplementedException(); + return parent.DbContext.runes.Where(r => r.RuneFamily.Equals(family)).Count(); } - public Task GetNbItemsByName(string substring) + public async Task GetNbItemsByName(string substring) { - throw new NotImplementedException(); + return parent.DbContext.runes.Where(r => r.Name.Contains(substring)).Count(); } - public Task UpdateItem(Model.Rune? oldItem, Model.Rune? newItem) + public async Task UpdateItem(Rune? oldItem, Rune? newItem) { - throw new NotImplementedException(); + parent.DbContext.runes.Remove(oldItem.ToEntity()); + parent.DbContext.runes.Add(newItem.ToEntity()); + return newItem; } } } diff --git a/EntityFramework_LoL/Sources/Business/DbData.Skins.cs b/EntityFramework_LoL/Sources/Business/DbData.Skins.cs index 7988141..4a0a965 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.Skins.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.Skins.cs @@ -1,9 +1,5 @@ -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using API_LoL_Project.Mapper; +using Model; namespace Business { @@ -16,49 +12,61 @@ namespace Business public SkinsManager(DbData parent) => this.parent = parent; - public Task AddItem(Skin? item) + public async Task AddItem(Skin? item) { - throw new NotImplementedException(); + await parent.DbContext.skins.AddAsync(item.ToEntity()); + return item; } - public Task DeleteItem(Skin? item) + public async Task DeleteItem(Skin? item) { - throw new NotImplementedException(); + parent.DbContext.skins.Remove(item.ToEntity()); + return true; } - public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.skins + .Select(s => s.ToModel()) + .Skip(index * count).Take(count); } - public Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + return parent.DbContext.skins.Where(s => s.Champion.Name.Equals(champion.Name)) + .Select(s => s.ToModel()) + .Skip(index * count).Take(count); } - 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) { - throw new NotImplementedException(); + return parent.DbContext.skins.Where(s => s.Name.Contains(substring)) + .Select(s => s.ToModel()) + .Skip(index * count).Take(count); } - public Task GetNbItems() + public async Task GetNbItems() { - throw new NotImplementedException(); + return parent.DbContext.skins.Count(); } - public Task GetNbItemsByChampion(Champion? champion) + public async Task GetNbItemsByChampion(Champion? champion) { - throw new NotImplementedException(); + return parent.DbContext.skins.Where(s => s.Champion.Name.Equals(champion.Name)) + .Count(); } - public Task GetNbItemsByName(string substring) + public async Task GetNbItemsByName(string substring) { - throw new NotImplementedException(); + return parent.DbContext.skins.Where(s => s.Name.Contains(substring)) + .Count(); } - public Task UpdateItem(Skin? oldItem, Skin? newItem) + public async Task UpdateItem(Skin? oldItem, Skin? newItem) { - throw new NotImplementedException(); + parent.DbContext.skins.Remove(oldItem.ToEntity()); + parent.DbContext.skins.Add(newItem.ToEntity()); + return newItem; } } } diff --git a/EntityFramework_LoL/Sources/Business/DbData.cs b/EntityFramework_LoL/Sources/Business/DbData.cs index 708039d..99c30e9 100644 --- a/EntityFramework_LoL/Sources/Business/DbData.cs +++ b/EntityFramework_LoL/Sources/Business/DbData.cs @@ -1,17 +1,22 @@ -using Model; +using Entities; +using Microsoft.EntityFrameworkCore; +using Model; namespace Business { public partial class DbData : IDataManager { - public DbData() + public DbData(LolDbContext dbContext) { + DbContext = dbContext; ChampionsMgr = new ChampionsManager(this); SkinsMgr = new SkinsManager(this); RunesMgr = new RunesManager(this); RunePagesMgr = new RunePagesManager(this); } + protected LolDbContext DbContext{ get; } + public IChampionsManager ChampionsMgr { get; } public ISkinsManager SkinsMgr { get; } diff --git a/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs b/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs index 5e3101a..42c060c 100644 --- a/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs +++ b/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs @@ -1,4 +1,5 @@ using Shared; +using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -15,14 +16,12 @@ namespace Entities public string? Icon { get; set; } [Required] public ChampionClass Class { get; set;} - public virtual ICollection? Skills { get; set; } + public virtual ICollection Skills { get; set; } + public virtual ICollection Characteristics { get; set; } + public ICollection runepages { get; set; } public Guid? ImageId { get; set; } - [ForeignKey("ImageId")] public LargeImageEntity? Image { get; set; } - - - } } diff --git a/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs b/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs new file mode 100644 index 0000000..8ad635c --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entities +{ + public class CharacteristicEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + public int Value { get; set; } + + [Required] + public string ChampionForeignKey { get; set; } + + [Key] + [Required] + [ForeignKey("ChampionForeignKey")] + public ChampionEntity Champion { get; set; } + } +} \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db index 5847519f33f10f07991fe63c42421d6b8cbacc6f..1c7c62bb20936b0f9beb7ac33bc42d9d9ec903f8 100644 GIT binary patch literal 110592 zcmeI5Uu+x4oyT`ci4-X=*S1Wr)m)%8g}`BAIb4afqK81GsHMx3EGeX1+sFlrEwz?- zrbv~ff-2V*pz1?j3KaKJT$86O(1!w--21)d+ADA<(gH;vn!FW7Q5^0J+yQq9?s^Y5 zJNt*b_dsit z&CZ&>OVj-Oq+&%aY^rj3ZCSl5ryp~CT3%n1)59gC=DMD@>W{jRPS!eYwP5Bdv*1i$AV&D>@VtFW4qNpNE1 zfO0Z&MJ=fnb*-pYJyfWAw$d3>$jj=gN~B*bREvdW^+c|8`fV!62|KzW7dmF~Wu74(=+xTvy)J3v3{{nD%v~Gpdd)}^ScTO=simD(Rcf`3 z`gU{0AhHZpwbLcod;5C##z3@1W6)}DhZIzRUsVAXesQ^(9aX!*^0K^X=@2o&z0W6BT97MWojxmWr$*75aAmVOEGri;Mg_E!r13p$>JP%pFO;rkHkp zojE2)bwO3L+djg;Tc<>qPL@M%4|YV3p_Mi1iaZ4|`Xc9$p}Ye$WP2PeA8V(-{%Vd4 zPp%xcU!-OUJm2}r?~ylXUl(N^d6X|iU9Tr2lCj8A7uzj`xl26Ejnf|M;Z3SSdL=<$ z5`J~jw7!y#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c;B%QlvEJmu3CbluWwwKOTpX!B?Cs@+V!Z delta 1128 zcma)6eP|PB7{BLoxy#4h`y@@XON^Q`n=_TBYx)&Ch?;hX6jN6^!3`-{Y=bSUu{05u zePB~6`&W6vtF@*0_0L2q-XDS>W9ZzIT;>A&J&yc>*OVHWSDeb6yj}j? zyVtwyKI;uiaknm96n}L*b!7N^X2#dX^Ob-xI}MFcXDm)bwzs;oPErr0q1roA94dU? z^Kq{KM6sY3%OmBArS;{Hu3EWqW|j`*j}VSBc6H*Q^`y|`$_J#E9d7|dp`?aU>ujW#L|wq+fX z8jZr_QM+z%IDc$x11a0POcHVS zcwN>5R+z{{2FRG8cul4;ig$|@py;BCwPasZ=$q=cLw)yKo{p@QXM$MVGhja^M0Qx z^gY0))UH%ZXIDl~ba%EU6K$DPd!n#hCl493{Q&n0i{{S)8& z9~IVEJl^NdHH=CJ+;mfD|@=TZ#K_)CA2GYA>T_`#^kuiNhDT#F|<^ ihQJ#;GM%j2R?Pc`cr5?TtPidt{dXY<9usOS(f91 diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm index be1302a557fa43b70c65f795a052420bbca6facd..559b34c146234d314364ab8716809d95949fd17d 100644 GIT binary patch delta 93 zcmZo@U}|V!;*@x#%K!!wIpqcYW(oezD8HeMET{_;1kwMI07R650W3f9toOzX G2K4~uVI7 - + diff --git a/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs b/EntityFramework_LoL/Sources/Entities/LolDbContext.cs similarity index 86% rename from EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs rename to EntityFramework_LoL/Sources/Entities/LolDbContext.cs index e28b10f..52b49a5 100644 --- a/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs +++ b/EntityFramework_LoL/Sources/Entities/LolDbContext.cs @@ -6,10 +6,11 @@ using System.Xml.Linq; namespace Entities { - public class ChampionDbContext : DbContext + public class LolDbContext : DbContext { public DbSet skins { get; set; } public DbSet champions { get; set; } + public DbSet characteristics { get; set; } public DbSet skills { get; set; } public DbSet runes { get; set; } public DbSet runepages { get; set; } @@ -58,6 +59,21 @@ namespace Entities } }); + modelBuilder.Entity().HasData(new List() { + new() + { + Name = "Force", + Value = 50, + ChampionForeignKey = "Dave", + }, + new() + { + Name = "Défense", + Value = 75, + ChampionForeignKey = "Armure", + } + }); + modelBuilder.Entity().HasData(new List() { new SkinEntity { diff --git a/EntityFramework_LoL/Sources/Entities/Program.cs b/EntityFramework_LoL/Sources/Entities/Program.cs index 6e4348a..13fdf1b 100644 --- a/EntityFramework_LoL/Sources/Entities/Program.cs +++ b/EntityFramework_LoL/Sources/Entities/Program.cs @@ -7,7 +7,7 @@ ChampionEntity imri = new() Bio = "Fou Furieux", Class = ChampionClass.Assassin }; -using (var context = new ChampionDbContext()) +using (var context = new LolDbContext()) { // Crée des nounours et les insère dans la base Console.WriteLine("Creates and inserts new Champion"); diff --git a/EntityFramework_LoL/Sources/Entities/RunePageEntity.cs b/EntityFramework_LoL/Sources/Entities/RunePageEntity.cs index ce2ae88..1c248ab 100644 --- a/EntityFramework_LoL/Sources/Entities/RunePageEntity.cs +++ b/EntityFramework_LoL/Sources/Entities/RunePageEntity.cs @@ -10,7 +10,6 @@ namespace Entities { public class RunePageEntity { - [Key] public Guid Id { get; set; } @@ -18,6 +17,7 @@ namespace Entities public string Name { get; set; } public ICollection runes { get; set; } + public ICollection champions { get; set; } }