diff --git a/.vs/League-of-Legends_Project3/v17/.wsuo b/.vs/League-of-Legends_Project3/v17/.wsuo index 80c36fc..0700017 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 new file mode 100644 index 0000000..ac7fce7 --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/Business.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + + diff --git a/EntityFramework_LoL/Sources/Business/DbData.Champions.cs b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs new file mode 100644 index 0000000..0c31b3f --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/DbData.Champions.cs @@ -0,0 +1,136 @@ +using API_LoL_Project.Mapper; +using Model; +using Shared; +using System.Data.SqlTypes; + +namespace Business +{ + public partial class DbData + { + public class ChampionsManager : IChampionsManager + { + private readonly DbData parent; + + public ChampionsManager(DbData parent) + => this.parent = parent; + + public async Task AddItem(Champion? item) + { + await parent.DbContext.champions.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(Champion? item) + { + parent.DbContext.champions.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => true, + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + } + + public async Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => c.Characteristics.Any(ch => ch.Name.Equals(charName)), + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + } + + public async Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => c.Class.Equals(championClass), + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + } + + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => c.Name.Contains(substring), + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + } + + public async Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity())), + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + + } + + public async Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name)), + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + } + + public async Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.champions.GetItemsWithFilterAndOrdering( + c => skill != null && c.Skills.Any(s => s.Name.Equals(skill)), + index, count, + orderingPropertyName, descending).Select(c => c.ToModel()); + } + + public async Task GetNbItems() + { + return parent.DbContext.champions.Count(); + } + + public async Task GetNbItemsByCharacteristic(string charName) + { + return parent.DbContext.champions.Where(c => c.Characteristics.Any(ch => ch.Name.Equals(charName))).Count(); + } + + public async Task GetNbItemsByClass(ChampionClass championClass) + { + return parent.DbContext.champions.Where(c => c.Class.Equals(championClass)) + .Count(); + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.champions.Where(c => c.Name.Contains(substring)) + .Count(); + } + + public async Task GetNbItemsByRunePage(RunePage? runePage) + { + return parent.DbContext.champions.Where(c => c.runepages.Any(rp => rp.Equals(runePage.ToEntity()))).Count(); + + } + + public async Task GetNbItemsBySkill(Skill? skill) + { + return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name))) + .Count(); + } + + public async Task GetNbItemsBySkill(string skill) + { + return parent.DbContext.champions.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill))) + .Count(); + } + + public async Task UpdateItem(Champion? oldItem, Champion? newItem) + { + 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 new file mode 100644 index 0000000..3de4937 --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/DbData.RunePages.cs @@ -0,0 +1,91 @@ +using API_LoL_Project.Mapper; +using Model; +using System.Data.SqlTypes; +using System.Linq; + +namespace Business +{ + public partial class DbData + { + public class RunePagesManager : IRunePagesManager + { + private readonly DbData parent; + + public RunePagesManager(DbData parent) + => this.parent = parent; + + public async Task AddItem(RunePage? item) + { + await parent.DbContext.runepages.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(RunePage? item) + { + parent.DbContext.runepages.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runepages.GetItemsWithFilterAndOrdering( + rp => true, + index, count, + orderingPropertyName, descending).Select(rp => rp.ToModel()); + } + + public async Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runepages.GetItemsWithFilterAndOrdering( + rp => rp.champions.Any(c => c.Name.Equals(champion.Name)), + index, count, + orderingPropertyName, descending).Select(rp => rp.ToModel()); + } + + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runepages.GetItemsWithFilterAndOrdering( + rp => rp.Name.Contains(substring), + index, count, + orderingPropertyName, descending).Select(rp => rp.ToModel()); + } + + public async Task> GetItemsByRune(Rune? rune, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runepages.GetItemsWithFilterAndOrdering( + rp => rp.runes.Any(r => r.Name.Equals(rune.Name)), + index, count, + orderingPropertyName, descending).Select(rp => rp.ToModel()); + } + + public async Task GetNbItems() + { + return parent.DbContext.runepages.Count(); + + } + + public async Task GetNbItemsByChampion(Champion? champion) + { + return parent.DbContext.runepages.Where(rp => rp.champions.Any(c => c.Name.Equals(champion.Name))).Count(); + + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.runepages.Where(rp => rp.Name.Contains(substring)).Count(); + } + + public async Task GetNbItemsByRune(Model.Rune? rune) + { + return parent.DbContext.runepages.Where(rp => rp.runes.Any(r => r.Name.Equals(rune.Name))).Count(); + } + + public async Task UpdateItem(RunePage? oldItem, RunePage? newItem) + { + 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 new file mode 100644 index 0000000..9c97b23 --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/DbData.Runes.cs @@ -0,0 +1,75 @@ +using API_LoL_Project.Mapper; +using API_LoL_Project.Mapper.API_LoL_Project.Mapper; +using Model; +using Shared; + +namespace Business +{ + public partial class DbData + { + public class RunesManager : IRunesManager + { + private readonly DbData parent; + + public RunesManager(DbData parent) + => this.parent = parent; + public async Task AddItem(Rune? item) + { + await parent.DbContext.runes.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(Rune? item) + { + parent.DbContext.runes.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runes.GetItemsWithFilterAndOrdering( + r => true, + index, count, + orderingPropertyName, descending).Select(r => r.ToModel()); + } + + public async Task> GetItemsByFamily(RuneFamily family, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runes.GetItemsWithFilterAndOrdering( + r => r.RuneFamily.Equals(family), + index, count, + orderingPropertyName, descending).Select(r => r.ToModel()); + } + + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.runes.GetItemsWithFilterAndOrdering( + r => r.Name.Contains(substring), + index, count, + orderingPropertyName, descending).Select(r => r.ToModel()); + } + + public async Task GetNbItems() + { + return parent.DbContext.runes.Count(); + } + + public async Task GetNbItemsByFamily(RuneFamily family) + { + return parent.DbContext.runes.Where(r => r.RuneFamily.Equals(family)).Count(); + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.runes.Where(r => r.Name.Contains(substring)).Count(); + } + + public async Task UpdateItem(Rune? oldItem, Rune? newItem) + { + 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 new file mode 100644 index 0000000..47b7ada --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/DbData.Skins.cs @@ -0,0 +1,78 @@ +using API_LoL_Project.Mapper; +using API_LoL_Project.Mapper.API_LoL_Project.Mapper; +using Model; +using System.Data.SqlTypes; + +namespace Business +{ + public partial class DbData + { + public class SkinsManager : ISkinsManager + { + private readonly DbData parent; + + public SkinsManager(DbData parent) + => this.parent = parent; + + public async Task AddItem(Skin? item) + { + await parent.DbContext.skins.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(Skin? item) + { + parent.DbContext.skins.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.skins.GetItemsWithFilterAndOrdering( + s => true, + index, count, + orderingPropertyName, descending).Select(s => s.ToModel()); + } + + public async Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.skins.GetItemsWithFilterAndOrdering( + s => s.Champion.Name.Equals(champion.Name), + index, count, + orderingPropertyName, descending).Select(s => s.ToModel()); + } + + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.skins.GetItemsWithFilterAndOrdering( + s => s.Name.Contains(substring), + index, count, + orderingPropertyName, descending).Select(s => s.ToModel()); + } + + public async Task GetNbItems() + { + return parent.DbContext.skins.Count(); + } + + public async Task GetNbItemsByChampion(Champion? champion) + { + return parent.DbContext.skins.Where(s => s.Champion.Name.Equals(champion.Name)) + .Count(); + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.skins.Where(s => s.Name.Contains(substring)) + .Count(); + } + + public async Task UpdateItem(Skin? oldItem, Skin? newItem) + { + 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 new file mode 100644 index 0000000..99c30e9 --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/DbData.cs @@ -0,0 +1,28 @@ +using Entities; +using Microsoft.EntityFrameworkCore; +using Model; + +namespace Business +{ + public partial class DbData : IDataManager + { + + 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; } + + public IRunesManager RunesMgr { get; } + + public IRunePagesManager RunePagesMgr { get; } + } +} \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/Business/Extensions.cs b/EntityFramework_LoL/Sources/Business/Extensions.cs new file mode 100644 index 0000000..9f99257 --- /dev/null +++ b/EntityFramework_LoL/Sources/Business/Extensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Business +{ + static class Extensions + { + internal static IEnumerable GetItemsWithFilterAndOrdering(this IEnumerable collection, + Func filter, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + IEnumerable temp = collection; + temp = temp.Where(item => filter(item)); + if (orderingPropertyName != null) + { + var prop = typeof(T).GetProperty(orderingPropertyName!); + if (prop != null) + { + temp = descending ? temp.OrderByDescending(item => prop.GetValue(item)) + : temp.OrderBy(item => prop.GetValue(item)); + } + } + return temp.Skip(index * count).Take(count) + } + } +} 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..e780845 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/CharacteristicEntity.cs @@ -0,0 +1,26 @@ +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; } + + [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..9ee7a58 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..927dd66 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.Champions.db-wal b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal index d2719b5..50a0bc3 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal 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 82% rename from EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs rename to EntityFramework_LoL/Sources/Entities/LolDbContext.cs index e28b10f..52795fd 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; } @@ -25,6 +26,7 @@ namespace Entities { modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(c => new { c.Name, c.ChampionForeignKey }); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity() @@ -32,6 +34,12 @@ namespace Entities .WithMany(x => x.runepages) .UsingEntity(); + modelBuilder.Entity() + .HasMany(x => x.runepages) + .WithMany(x => x.champions); + + + modelBuilder.Entity().HasData(new List() { @@ -58,6 +66,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/Migrations/20230209133904_myFirstMigration.Designer.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.Designer.cs similarity index 77% rename from EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.Designer.cs rename to EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.Designer.cs index 81f4297..e62e66e 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.Designer.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.Designer.cs @@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Entities.Migrations { - [DbContext(typeof(ChampionDbContext))] - [Migration("20230209133904_myFirstMigration")] + [DbContext(typeof(LolDbContext))] + [Migration("20230301162639_myFirstMigration")] partial class myFirstMigration { /// @@ -20,6 +20,21 @@ namespace Entities.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("championsName") + .HasColumnType("TEXT"); + + b.Property("runepagesId") + .HasColumnType("TEXT"); + + b.HasKey("championsName", "runepagesId"); + + b.HasIndex("runepagesId"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.Property("ChampionsName") @@ -76,6 +91,39 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name", "ChampionForeignKey"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("characteristics"); + + b.HasData( + new + { + Name = "Force", + ChampionForeignKey = "Dave", + Value = 50 + }, + new + { + Name = "Défense", + ChampionForeignKey = "Armure", + Value = 75 + }); + }); + modelBuilder.Entity("Entities.LargeImageEntity", b => { b.Property("Id") @@ -93,7 +141,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), + Id = new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), Base64 = "aaa" }); }); @@ -154,7 +202,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), + Id = new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), Name = "Runepage_1" }); }); @@ -262,6 +310,21 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("championsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("runepagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.HasOne("Entities.ChampionEntity", null) @@ -286,6 +349,17 @@ namespace Entities.Migrations b.Navigation("Image"); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.HasOne("Entities.ChampionEntity", "Champion") + .WithMany("Characteristics") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + modelBuilder.Entity("Entities.RuneEntity", b => { b.HasOne("Entities.LargeImageEntity", "Image") @@ -326,6 +400,11 @@ namespace Entities.Migrations b.Navigation("Image"); }); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Navigation("Characteristics"); + }); #pragma warning restore 612, 618 } } diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.cs similarity index 77% rename from EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.cs rename to EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.cs index eb3748a..e3dd73d 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/20230209133904_myFirstMigration.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230301162639_myFirstMigration.cs @@ -89,6 +89,30 @@ namespace Entities.Migrations principalColumn: "Id"); }); + migrationBuilder.CreateTable( + name: "ChampionEntityRunePageEntity", + columns: table => new + { + championsName = table.Column(type: "TEXT", nullable: false), + runepagesId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionEntityRunePageEntity", x => new { x.championsName, x.runepagesId }); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_champions_championsName", + column: x => x.championsName, + principalTable: "champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ChampionEntityRunePageEntity_runepages_runepagesId", + column: x => x.runepagesId, + principalTable: "runepages", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "ChampionEntitySkillEntity", columns: table => new @@ -113,6 +137,25 @@ namespace Entities.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "characteristics", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + ChampionForeignKey = table.Column(type: "TEXT", nullable: false), + Value = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_characteristics", x => new { x.Name, x.ChampionForeignKey }); + table.ForeignKey( + name: "FK_characteristics_champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, + principalTable: "champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "skins", columns: table => new @@ -177,12 +220,12 @@ namespace Entities.Migrations migrationBuilder.InsertData( table: "largeimages", columns: new[] { "Id", "Base64" }, - values: new object[] { new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), "aaa" }); + values: new object[] { new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), "aaa" }); migrationBuilder.InsertData( table: "runepages", columns: new[] { "Id", "Name" }, - values: new object[] { new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), "Runepage_1" }); + values: new object[] { new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), "Runepage_1" }); migrationBuilder.InsertData( table: "runes", @@ -202,6 +245,15 @@ namespace Entities.Migrations { "White Star", "Random damage", 3 } }); + migrationBuilder.InsertData( + table: "characteristics", + columns: new[] { "ChampionForeignKey", "Name", "Value" }, + values: new object[,] + { + { "Armure", "Défense", 75 }, + { "Dave", "Force", 50 } + }); + migrationBuilder.InsertData( table: "skins", columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "ImageId", "Price" }, @@ -211,6 +263,11 @@ namespace Entities.Migrations { "Dave de glace", "Dave", "Enneigé", "aaa", null, 7.99f } }); + migrationBuilder.CreateIndex( + name: "IX_ChampionEntityRunePageEntity_runepagesId", + table: "ChampionEntityRunePageEntity", + column: "runepagesId"); + migrationBuilder.CreateIndex( name: "IX_ChampionEntitySkillEntity_SkillsName", table: "ChampionEntitySkillEntity", @@ -221,6 +278,11 @@ namespace Entities.Migrations table: "champions", column: "ImageId"); + migrationBuilder.CreateIndex( + name: "IX_characteristics_ChampionForeignKey", + table: "characteristics", + column: "ChampionForeignKey"); + migrationBuilder.CreateIndex( name: "IX_RunePageRuneEntity_runesName", table: "RunePageRuneEntity", @@ -245,9 +307,15 @@ namespace Entities.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "ChampionEntityRunePageEntity"); + migrationBuilder.DropTable( name: "ChampionEntitySkillEntity"); + migrationBuilder.DropTable( + name: "characteristics"); + migrationBuilder.DropTable( name: "RunePageRuneEntity"); diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs b/EntityFramework_LoL/Sources/Entities/Migrations/LolDbContextModelSnapshot.cs similarity index 77% rename from EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs rename to EntityFramework_LoL/Sources/Entities/Migrations/LolDbContextModelSnapshot.cs index aef1440..e343e94 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/LolDbContextModelSnapshot.cs @@ -9,14 +9,29 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Entities.Migrations { - [DbContext(typeof(ChampionDbContext))] - partial class ChampionDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(LolDbContext))] + partial class LolDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.Property("championsName") + .HasColumnType("TEXT"); + + b.Property("runepagesId") + .HasColumnType("TEXT"); + + b.HasKey("championsName", "runepagesId"); + + b.HasIndex("runepagesId"); + + b.ToTable("ChampionEntityRunePageEntity"); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.Property("ChampionsName") @@ -73,6 +88,39 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("INTEGER"); + + b.HasKey("Name", "ChampionForeignKey"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("characteristics"); + + b.HasData( + new + { + Name = "Force", + ChampionForeignKey = "Dave", + Value = 50 + }, + new + { + Name = "Défense", + ChampionForeignKey = "Armure", + Value = 75 + }); + }); + modelBuilder.Entity("Entities.LargeImageEntity", b => { b.Property("Id") @@ -90,7 +138,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("70d7aace-13a9-40e1-bd94-99790805f6d0"), + Id = new Guid("d3a490c6-fb49-475a-9134-47c2de9888d2"), Base64 = "aaa" }); }); @@ -151,7 +199,7 @@ namespace Entities.Migrations b.HasData( new { - Id = new Guid("a5a4f69b-5cbb-48c1-beb4-896bc9171714"), + Id = new Guid("4ea04d4f-0a64-4d28-8d74-4499dbc541f2"), Name = "Runepage_1" }); }); @@ -259,6 +307,21 @@ namespace Entities.Migrations }); }); + modelBuilder.Entity("ChampionEntityRunePageEntity", b => + { + b.HasOne("Entities.ChampionEntity", null) + .WithMany() + .HasForeignKey("championsName") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.RunePageEntity", null) + .WithMany() + .HasForeignKey("runepagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("ChampionEntitySkillEntity", b => { b.HasOne("Entities.ChampionEntity", null) @@ -283,6 +346,17 @@ namespace Entities.Migrations b.Navigation("Image"); }); + modelBuilder.Entity("Entities.CharacteristicEntity", b => + { + b.HasOne("Entities.ChampionEntity", "Champion") + .WithMany("Characteristics") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); + modelBuilder.Entity("Entities.RuneEntity", b => { b.HasOne("Entities.LargeImageEntity", "Image") @@ -323,6 +397,11 @@ namespace Entities.Migrations b.Navigation("Image"); }); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Navigation("Characteristics"); + }); #pragma warning restore 612, 618 } } 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; } } diff --git a/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln index 5e32aeb..5abb419 100644 --- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{7 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Entity Framework", "Entity Framework", "{BC2FFCA4-3801-433F-A83E-B55345F3B31E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{C463E2E1-237A-4339-A4C4-6EA3BE7002AE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,6 +59,10 @@ Global {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.Build.0 = Release|Any CPU + {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -65,6 +71,7 @@ Global {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} {C463E2E1-237A-4339-A4C4-6EA3BE7002AE} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E} + {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3} = {BC2FFCA4-3801-433F-A83E-B55345F3B31E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}