diff --git a/.vs/League-of-Legends_Project3/v17/.wsuo b/.vs/League-of-Legends_Project3/v17/.wsuo index 80c36fc..4fd9423 100644 Binary files a/.vs/League-of-Legends_Project3/v17/.wsuo and b/.vs/League-of-Legends_Project3/v17/.wsuo differ 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 5847519..1c7c62b 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm index be1302a..559b34c 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-shm differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.csproj b/EntityFramework_LoL/Sources/Entities/Entities.csproj index ef6f098..454775c 100644 --- a/EntityFramework_LoL/Sources/Entities/Entities.csproj +++ b/EntityFramework_LoL/Sources/Entities/Entities.csproj @@ -22,7 +22,7 @@ - + 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; } }