From 096dc87b5fe3de2a3f981be9be54260420ae28da Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Fri, 3 Mar 2023 15:25:57 +0100 Subject: [PATCH 1/2] API Skill (Mapper+Controller) --- .../APILOL/Controllers/ChampionsController.cs | 7 +- Sources/APILOL/Mapper/ChampionMapper.cs | 7 +- Sources/DTO/ChampionDTO.cs | 17 +++- Sources/DTO/DTO.csproj | 4 + Sources/DTO/SkillDTO.cs | 18 +++++ .../DBContexts/SQLiteContext.cs | 1 + .../EntityFrameworkLOL/Entities/RuneEntity.cs | 2 + .../Entities/RunePageEntity.cs | 2 + Sources/EntityFrameworkLOL/Program.cs | 81 +++++++++++++++++-- 9 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 Sources/DTO/SkillDTO.cs diff --git a/Sources/APILOL/Controllers/ChampionsController.cs b/Sources/APILOL/Controllers/ChampionsController.cs index b73d518..a64d8ca 100644 --- a/Sources/APILOL/Controllers/ChampionsController.cs +++ b/Sources/APILOL/Controllers/ChampionsController.cs @@ -68,9 +68,4 @@ namespace APILOL.Controllers return Ok(dataManager.DeleteItem(dtos.First())); } } -} - -/* -var champion = new Champion(""); -var dto = ChampionMapper.ToDto(champion); -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/Sources/APILOL/Mapper/ChampionMapper.cs b/Sources/APILOL/Mapper/ChampionMapper.cs index 883052c..b2d257d 100644 --- a/Sources/APILOL/Mapper/ChampionMapper.cs +++ b/Sources/APILOL/Mapper/ChampionMapper.cs @@ -11,12 +11,17 @@ namespace APILOL.Mapper { Name = champion.Name, Bio = champion.Bio, + Class = champion.Class, + Icon = champion.Icon, + Image = champion.Image, + Characteristics = champion.Characteristics, + Skills = champion.Skills, }; } public static Champion ToModel(this ChampionDTO champion) { - return new Champion(champion.Name); + return new Champion(champion.Name/*, champion.Class, champion.Icon, champion.Image.ToString(), champion.Bio*/); } } } diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs index 2a8f880..12eb51f 100644 --- a/Sources/DTO/ChampionDTO.cs +++ b/Sources/DTO/ChampionDTO.cs @@ -1,8 +1,23 @@ -namespace DTO +using Model; +using System.Collections.Immutable; +using System.Collections.ObjectModel; + +namespace DTO { public class ChampionDTO { public string Name { get; set; } + public string Bio { get; set; } + + public ChampionClass Class { get; set; } + + public string Icon { get; set; } + + public LargeImage Image { get; set; } + + public ReadOnlyDictionary Characteristics { get; set; } + + public ImmutableHashSet Skills { get; set; } } } \ No newline at end of file diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj index 94a926e..5c5bf12 100644 --- a/Sources/DTO/DTO.csproj +++ b/Sources/DTO/DTO.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/Sources/DTO/SkillDTO.cs b/Sources/DTO/SkillDTO.cs new file mode 100644 index 0000000..0f53f56 --- /dev/null +++ b/Sources/DTO/SkillDTO.cs @@ -0,0 +1,18 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkillDTO + { + public SkillType Type { get; set; } + + public string Name { get; set; } + + public string Description { get; set; } + } +} diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs index 342cb78..8c0db8e 100644 --- a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -22,6 +22,7 @@ namespace EntityFrameworkLOL.DBContexts protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); + // Fluent API } public SQLiteContext() diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs index f313cdf..fac287d 100644 --- a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -18,5 +18,7 @@ namespace EntityFrameworkLOL.Entities public ImageEntity Image { get; set; } public RuneFamilyEntity Family { get; set; } + + public ICollection Pages { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs index e99dd61..af6d3b9 100644 --- a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs @@ -23,5 +23,7 @@ namespace EntityFrameworkLOL.Entities [NotMapped] public Dictionary Dictionary { get; set; } // Switch Dictionary to List puis faudra juste mapper la liste en dico + + public ICollection Entities { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index be3799b..07c35d6 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -8,6 +8,72 @@ class Program { static void Main(string[] args) { + using (var context = new SQLiteContext()) { + if (context.Champion.Count() > 0) + { + foreach (var c in context.Champion.ToArray()) + { + context.Champion.Remove(c); + } + } + if (context.Rune.Count() > 0) + { + foreach (var r in context.Rune.ToArray()) + { + context.Rune.Remove(r); + } + } + if (context.Skin.Count() > 0) + { + foreach (var s in context.Skin.ToArray()) + { + context.Skin.Remove(s); + } + } + if (context.Skill.Count() > 0) + { + foreach (var s in context.Skill.ToArray()) + { + context.Skill.Remove(s); + } + } + if (context.RunePage.Count() > 0) + { + foreach (var rp in context.RunePage.ToArray()) + { + context.RunePage.Remove(rp); + } + } + if (context.ChampionClass.Count() > 0) + { + foreach (var cc in context.ChampionClass.ToArray()) + { + context.ChampionClass.Remove(cc); + } + } + if (context.RuneFamily.Count() > 0) + { + foreach (var rf in context.RuneFamily.ToArray()) + { + context.RuneFamily.Remove(rf); + } + } + if (context.SkillType.Count() > 0) + { + foreach (var st in context.SkillType.ToArray()) + { + context.SkillType.Remove(st); + } + } + if (context.Image.Count() > 0) + { + foreach (var i in context.Image.ToArray()) + { + context.Image.Remove(i); + } + } + context.SaveChanges(); + } ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "" }; ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox", Bio = "" }; ChampionEntity ahri = new ChampionEntity { Name = "Ahri", Bio = "" }; @@ -19,12 +85,13 @@ class Program { // Crée des champions et les insère dans la base Console.WriteLine("Creates and inserts new Champions"); - context.Add(akali); + context.AddRange(new ChampionEntity[] { akali, aatrox, ahri, bard, alistar, akshan }); + /*context.Add(akali); context.Add(aatrox); context.Add(ahri); context.Add(bard); context.Add(alistar); - context.Add(akshan); + context.Add(akshan);*/ context.SaveChanges(); Console.WriteLine("Creates and executes a query retrieving the first Champion of the database whose name starts with an \"A\":"); var aChampion = context.Champion @@ -44,12 +111,13 @@ class Program { // Crée des Runes et les insère dans la base Console.WriteLine("Creates and inserts new Runes"); - context.Add(conqueror); + context.AddRange(new RuneEntity[] { conqueror, thriumph, alacrity, tenacity, laststand, laststand2 }); + /*context.Add(conqueror); context.Add(thriumph); context.Add(alacrity); context.Add(tenacity); context.Add(laststand); - context.Add(laststand2); + context.Add(laststand2);*/ context.SaveChanges(); Console.WriteLine("Creates and executes a query retrieving the first Runes of the database whose name starts with an \"L\":"); var lRune = context.Rune @@ -69,12 +137,13 @@ class Program { // Crée des Skins et les insère dans la base Console.WriteLine("Creates and inserts new Skins"); - context.Add(stinger); + context.AddRange(new SkinEntity[] { stinger, infernal, allStar, justicar, mecha, seaHunter }); + /*context.Add(stinger); context.Add(infernal); context.Add(allStar); context.Add(justicar); context.Add(mecha); - context.Add(seaHunter); + context.Add(seaHunter);*/ context.SaveChanges(); Console.WriteLine("Creates and executes a query retrieving the first Skins of the database whose name starts with an \"I\":"); var iSkin = context.Skin From 3fc3ddff6c296e22d446861dd52b166d56aa3488 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Tue, 7 Mar 2023 19:22:17 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Push=20Modif=20EF=20+=20Manager=20EF=20(man?= =?UTF-8?q?que=20modif=20Mapper=20=C3=A0=20pull)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/APILOL/APILOL.csproj | 1 + Sources/APILOL/Mapper/ChampionMapper.cs | 20 +- .../DBContexts/SQLiteContext.cs | 111 ++++++- .../Entities/CategoryEntity.cs | 24 -- .../Entities/ChampionEntity.cs | 15 +- ...ClassEntity.cs => CharacteristicEntity.cs} | 24 +- .../Entities/ImageEntity.cs | 2 +- .../EntityFrameworkLOL/Entities/RuneEntity.cs | 8 +- .../Entities/RuneFamilyEntity.cs | 21 -- .../Entities/RunePageEntity.cs | 8 +- .../Entities/RunePageRuneEntity.cs | 15 + .../Entities/SkillEntity.cs | 7 +- .../Entities/SkillTypeEntity.cs | 21 -- .../EntityFrameworkLOL/Entities/SkinEntity.cs | 2 +- ...0230209135613_MigrationWallah5.Designer.cs | 291 ------------------ .../20230209135613_MigrationWallah5.cs | 284 ----------------- .../Migrations/SQLiteContextModelSnapshot.cs | 288 ----------------- Sources/LeagueOfLegends.sln | 8 +- Sources/ManagersEF/EFManager.Champions.cs | 136 ++++++++ Sources/ManagersEF/EFManager.RunePages.cs | 92 ++++++ Sources/ManagersEF/EFManager.Runes.cs | 74 +++++ Sources/ManagersEF/EFManager.Skins.cs | 77 +++++ Sources/ManagersEF/EFManager.cs | 28 ++ Sources/ManagersEF/Extensions.cs | 28 ++ Sources/ManagersEF/ManagersEF.csproj | 15 + 25 files changed, 624 insertions(+), 976 deletions(-) delete mode 100644 Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs rename Sources/EntityFrameworkLOL/Entities/{ChampionClassEntity.cs => CharacteristicEntity.cs} (55%) delete mode 100644 Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs create mode 100644 Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs delete mode 100644 Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs delete mode 100644 Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.Designer.cs delete mode 100644 Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.cs delete mode 100644 Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs create mode 100644 Sources/ManagersEF/EFManager.Champions.cs create mode 100644 Sources/ManagersEF/EFManager.RunePages.cs create mode 100644 Sources/ManagersEF/EFManager.Runes.cs create mode 100644 Sources/ManagersEF/EFManager.Skins.cs create mode 100644 Sources/ManagersEF/EFManager.cs create mode 100644 Sources/ManagersEF/Extensions.cs create mode 100644 Sources/ManagersEF/ManagersEF.csproj diff --git a/Sources/APILOL/APILOL.csproj b/Sources/APILOL/APILOL.csproj index 607f65a..1904f25 100644 --- a/Sources/APILOL/APILOL.csproj +++ b/Sources/APILOL/APILOL.csproj @@ -20,6 +20,7 @@ + diff --git a/Sources/APILOL/Mapper/ChampionMapper.cs b/Sources/APILOL/Mapper/ChampionMapper.cs index b2d257d..d8c0bd5 100644 --- a/Sources/APILOL/Mapper/ChampionMapper.cs +++ b/Sources/APILOL/Mapper/ChampionMapper.cs @@ -1,4 +1,5 @@ using DTO; +using EntityFrameworkLOL.Entities; using Model; namespace APILOL.Mapper @@ -21,7 +22,24 @@ namespace APILOL.Mapper public static Champion ToModel(this ChampionDTO champion) { - return new Champion(champion.Name/*, champion.Class, champion.Icon, champion.Image.ToString(), champion.Bio*/); + return new Champion(champion.Name, champion.Class, champion.Icon, champion.Image.ToString(), champion.Bio); + } + + public static ChampionEntity ToEntity(this Champion item) + { + 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 ChampionEntity entity) + { + return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio); } } } diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs index 8c0db8e..8d9ad94 100644 --- a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -1,18 +1,15 @@ using EntityFrameworkLOL.Entities; using Microsoft.EntityFrameworkCore; +using Model; namespace EntityFrameworkLOL.DBContexts { - class SQLiteContext : DbContext + public class SQLiteContext : DbContext { - public DbSet Category { get; set; } - public DbSet RuneFamily { get; set; } public DbSet Image { get; set; } - public DbSet SkillType { get; set; } public DbSet Skill { get; set; } public DbSet Skin { get; set; } public DbSet Rune { get; set; } - public DbSet ChampionClass { get; set; } public DbSet RunePage { get; set; } public DbSet Champion { get; set; } @@ -21,15 +18,101 @@ namespace EntityFrameworkLOL.DBContexts protected override void OnModelCreating(ModelBuilder modelBuilder) { - base.OnModelCreating(modelBuilder); - // Fluent API - } - - public SQLiteContext() - { } + modelBuilder.Entity().Property(i => i.Base64).ValueGeneratedOnAdd(); + modelBuilder.Entity().HasKey(c => new { c.Name, c.Champion }); + modelBuilder.Entity().Property(rp => rp.Name).ValueGeneratedOnAdd(); + modelBuilder.Entity() + .HasMany(rp => rp.Runes) + .WithMany(r => r.RunePages) + .UsingEntity(); + modelBuilder.Entity() + .HasMany(c => c.RunePages) + .WithMany(rp => rp.Champions); + modelBuilder.Entity().HasData(new List() + { + new() + { + Base64 = "default" + } + }); + modelBuilder.Entity().HasData(new List() { + new() + { + Name = "WinKer", + Bio = "Best front-end designer", + Class = ChampionClass.Mage, - public SQLiteContext(DbContextOptions options) - : base(options) - { } + }, + new() + { + Name = "Jonquille", + Bio = "Daffodil", + Class = ChampionClass.Support, + } + }); + modelBuilder.Entity().HasData(new List() { + new() + { + Name = "Front-end", + Value = 100, + }, + new() + { + Name = "Back-end", + Value = 100, + } + }); + modelBuilder.Entity().HasData(new List() { + new SkinEntity + { + Name = "Darker WinKer", + Description = "Be invisible in the darkness but never alone", + Icon = "default", + Price=9.99F + }, + new SkinEntity + { + Name = "Summer Daffodil", + Description = "A jewel of Summer for all year long", + Icon = "default", + Price=9.99F + }, + }); + modelBuilder.Entity().HasData(new List() { + new() + { + Name = "Beautiful layout", + Description = "Bowl'In", + Type = SkillType.Ultimate + }, + new() + { + Name = "DB Support", + Description = "DB", + Type = SkillType.Basic + } + }); + modelBuilder.Entity().HasData(new List() + { + new() + { + Name="FirstRunepage" + } + }); + modelBuilder.Entity().HasData(new List() { + new() + { + Name = "Mastering of Blue", + Description = "Blue shades", + Family = RuneFamily.Domination + }, + new() + { + Name = "Empty Shards", + Description = "Remove runes", + Family = RuneFamily.Precision + } + }); + } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs b/Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs deleted file mode 100644 index caa6ded..0000000 --- a/Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Linq; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Text; -using System.ComponentModel.DataAnnotations; -using System.Xml.Linq; -using System.Collections.ObjectModel; -using System.ComponentModel.DataAnnotations.Schema; -using Model; -using static System.Net.Mime.MediaTypeNames; -using System.Reflection.PortableExecutable; -using System.Security.Claims; - -namespace EntityFrameworkLOL.Entities -{ - class CategoryEntity - { - [Key] - [ForeignKey("RunePageEntity")] - public RunePage.Category Category { get; set; } - } -} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs index 0fe0c2d..104744b 100644 --- a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs @@ -15,24 +15,25 @@ using System.Security.Claims; namespace EntityFrameworkLOL.Entities { - class ChampionEntity + public class ChampionEntity { [Key] public string Name { get; set; } + [Required] public string Bio { get; set; } public string Icon { get; set; } - [NotMapped] - public Dictionary Characteristics { get; set; } - // Switch Dictionary to List puis faudra juste mapper la liste en dico - - public ChampionClassEntity Class { get; set; } + [Required] + public ChampionClass Class { get; set; } public ImageEntity Image { get; set; } - //[NotMapped] public virtual ICollection Skills { get; set; } + + public virtual ICollection Characteristics { get; set; } + + public ICollection RunePages { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/ChampionClassEntity.cs b/Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs similarity index 55% rename from Sources/EntityFrameworkLOL/Entities/ChampionClassEntity.cs rename to Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs index 8a75e0d..7c7da71 100644 --- a/Sources/EntityFrameworkLOL/Entities/ChampionClassEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/CharacteristicEntity.cs @@ -1,21 +1,23 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Linq; -using System.Threading.Tasks; +using System; using System.Collections.Generic; -using System.Text; -using System.ComponentModel.DataAnnotations; -using Model; using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EntityFrameworkLOL.Entities; namespace EntityFrameworkLOL.Entities { - class ChampionClassEntity + public class CharacteristicEntity { [Key] - [ForeignKey("ChampionEntity")] - public int Id { get; set; } + public string Name { get; set; } - public ChampionClass Class { get; set; } + [Required] + public int Value { get; set; } + + [ForeignKey("ChampionEntity")] + public ChampionEntity Champion { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs b/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs index 07a6d91..a4c4eaf 100644 --- a/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs @@ -15,7 +15,7 @@ using System.Security.Claims; namespace EntityFrameworkLOL.Entities { - class ImageEntity + public class ImageEntity { [Key] [ForeignKey("ChampionEntity")] diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs index fac287d..83bef82 100644 --- a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -5,10 +5,11 @@ using System.Threading.Tasks; using System.Collections.Generic; using System.Text; using System.ComponentModel.DataAnnotations; +using Model; namespace EntityFrameworkLOL.Entities { - class RuneEntity + public class RuneEntity { [Key] public string Name { get; set; } @@ -17,8 +18,9 @@ namespace EntityFrameworkLOL.Entities public ImageEntity Image { get; set; } - public RuneFamilyEntity Family { get; set; } + [Required] + public RuneFamily Family { get; set; } - public ICollection Pages { get; set; } + public ICollection RunePages { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs deleted file mode 100644 index c7369ad..0000000 --- a/Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Linq; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Text; -using System.ComponentModel.DataAnnotations; -using Model; -using System.ComponentModel.DataAnnotations.Schema; - -namespace EntityFrameworkLOL.Entities -{ - class RuneFamilyEntity - { - [Key] - [ForeignKey("RuneEntity")] - public int Id { get; set; } - - public RuneFamily Family { get; set; } - } -} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs index af6d3b9..6c30ddf 100644 --- a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs @@ -15,15 +15,13 @@ using System.Security.Claims; namespace EntityFrameworkLOL.Entities { - class RunePageEntity + public class RunePageEntity { [Key] public string Name { get; set; } - [NotMapped] - public Dictionary Dictionary { get; set; } - // Switch Dictionary to List puis faudra juste mapper la liste en dico + public ICollection Runes { get; set; } - public ICollection Entities { get; set; } + public ICollection Champions { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs new file mode 100644 index 0000000..02e256d --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/RunePageRuneEntity.cs @@ -0,0 +1,15 @@ +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Model.RunePage; + +namespace EntityFrameworkLOL.Entities +{ + public class RunePageRuneEntity + { + public Category Category { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs index ef50aa2..222d4f2 100644 --- a/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs @@ -6,19 +6,20 @@ using System.Collections.Generic; using System.Text; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Model; namespace EntityFrameworkLOL.Entities { - class SkillEntity + public class SkillEntity { [Key] public string Name { get; set; } public string Description { get; set; } - public SkillTypeEntity Type { get; set; } + [Required] + public SkillType Type { get; set; } - //[NotMapped] public virtual ICollection Champions { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs deleted file mode 100644 index f182d33..0000000 --- a/Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Linq; -using System.Threading.Tasks; -using System.Collections.Generic; -using System.Text; -using System.ComponentModel.DataAnnotations; -using Model; -using System.ComponentModel.DataAnnotations.Schema; - -namespace EntityFrameworkLOL.Entities -{ - class SkillTypeEntity - { - [Key] - [ForeignKey("SkillEntity")] - public int Id { get; set; } - - public SkillType Type { get; set; } - } -} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs index d14983b..eb6496e 100644 --- a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs @@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations; namespace EntityFrameworkLOL.Entities { - class SkinEntity + public class SkinEntity { [Key] public string Name { get; set; } diff --git a/Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.Designer.cs deleted file mode 100644 index 6015393..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.Designer.cs +++ /dev/null @@ -1,291 +0,0 @@ -// -using EntityFrameworkLOL.DBContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - [DbContext(typeof(SQLiteContext))] - [Migration("20230209135613_MigrationWallah5")] - partial class MigrationWallah5 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("ChampionEntitySkillEntity", b => - { - b.Property("ChampionsName") - .HasColumnType("TEXT"); - - b.Property("SkillsName") - .HasColumnType("TEXT"); - - b.HasKey("ChampionsName", "SkillsName"); - - b.HasIndex("SkillsName"); - - b.ToTable("ChampionEntitySkillEntity"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.CategoryEntity", b => - { - b.Property("Category") - .HasColumnType("INTEGER"); - - b.HasKey("Category"); - - b.ToTable("Category"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionClassEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Class") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.ToTable("ChampionClass"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ClassId") - .HasColumnType("INTEGER"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageBase64") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.HasIndex("ClassId"); - - b.HasIndex("ImageBase64"); - - b.ToTable("Champion"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ImageEntity", b => - { - b.Property("Base64") - .HasColumnType("TEXT"); - - b.HasKey("Base64"); - - b.ToTable("Image"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("FamilyId") - .HasColumnType("INTEGER"); - - b.Property("ImageBase64") - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.HasIndex("FamilyId"); - - b.HasIndex("ImageBase64"); - - b.ToTable("Rune"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneFamilyEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Family") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.ToTable("RuneFamily"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RunePageEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("RunePage"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("TypeId") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("TypeId"); - - b.ToTable("Skill"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillTypeEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.ToTable("SkillType"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("ChampionSkinName") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageBase64") - .HasColumnType("TEXT"); - - b.Property("Price") - .HasColumnType("REAL"); - - b.HasKey("Name"); - - b.HasIndex("ChampionSkinName"); - - b.HasIndex("ImageBase64"); - - b.ToTable("Skin"); - }); - - modelBuilder.Entity("ChampionEntitySkillEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", null) - .WithMany() - .HasForeignKey("ChampionsName") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EntityFrameworkLOL.Entities.SkillEntity", null) - .WithMany() - .HasForeignKey("SkillsName") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.ChampionClassEntity", "Class") - .WithMany() - .HasForeignKey("ClassId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageBase64") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Class"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.RuneFamilyEntity", "Family") - .WithMany() - .HasForeignKey("FamilyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageBase64"); - - b.Navigation("Family"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.SkillTypeEntity", "Type") - .WithMany() - .HasForeignKey("TypeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Type"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "ChampionSkin") - .WithMany() - .HasForeignKey("ChampionSkinName"); - - b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageBase64"); - - b.Navigation("ChampionSkin"); - - b.Navigation("Image"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.cs b/Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.cs deleted file mode 100644 index 0e28b34..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/20230209135613_MigrationWallah5.cs +++ /dev/null @@ -1,284 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - /// - public partial class MigrationWallah5 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Category", - columns: table => new - { - Category = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Category", x => x.Category); - }); - - migrationBuilder.CreateTable( - name: "ChampionClass", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Class = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ChampionClass", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Image", - columns: table => new - { - Base64 = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Image", x => x.Base64); - }); - - migrationBuilder.CreateTable( - name: "RuneFamily", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Family = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_RuneFamily", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "RunePage", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_RunePage", x => x.Name); - }); - - migrationBuilder.CreateTable( - name: "SkillType", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Type = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_SkillType", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Champion", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Bio = table.Column(type: "TEXT", nullable: false), - Icon = table.Column(type: "TEXT", nullable: false), - ClassId = table.Column(type: "INTEGER", nullable: false), - ImageBase64 = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champion", x => x.Name); - table.ForeignKey( - name: "FK_Champion_ChampionClass_ClassId", - column: x => x.ClassId, - principalTable: "ChampionClass", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Champion_Image_ImageBase64", - column: x => x.ImageBase64, - principalTable: "Image", - principalColumn: "Base64", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Rune", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - ImageBase64 = table.Column(type: "TEXT", nullable: true), - FamilyId = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Rune", x => x.Name); - table.ForeignKey( - name: "FK_Rune_Image_ImageBase64", - column: x => x.ImageBase64, - principalTable: "Image", - principalColumn: "Base64"); - table.ForeignKey( - name: "FK_Rune_RuneFamily_FamilyId", - column: x => x.FamilyId, - principalTable: "RuneFamily", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Skill", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - TypeId = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Skill", x => x.Name); - table.ForeignKey( - name: "FK_Skill_SkillType_TypeId", - column: x => x.TypeId, - principalTable: "SkillType", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Skin", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false), - Icon = table.Column(type: "TEXT", nullable: false), - Price = table.Column(type: "REAL", nullable: false), - ImageBase64 = table.Column(type: "TEXT", nullable: true), - ChampionSkinName = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Skin", x => x.Name); - table.ForeignKey( - name: "FK_Skin_Champion_ChampionSkinName", - column: x => x.ChampionSkinName, - principalTable: "Champion", - principalColumn: "Name"); - table.ForeignKey( - name: "FK_Skin_Image_ImageBase64", - column: x => x.ImageBase64, - principalTable: "Image", - principalColumn: "Base64"); - }); - - migrationBuilder.CreateTable( - name: "ChampionEntitySkillEntity", - columns: table => new - { - ChampionsName = table.Column(type: "TEXT", nullable: false), - SkillsName = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ChampionEntitySkillEntity", x => new { x.ChampionsName, x.SkillsName }); - table.ForeignKey( - name: "FK_ChampionEntitySkillEntity_Champion_ChampionsName", - column: x => x.ChampionsName, - principalTable: "Champion", - principalColumn: "Name", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_ChampionEntitySkillEntity_Skill_SkillsName", - column: x => x.SkillsName, - principalTable: "Skill", - principalColumn: "Name", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Champion_ClassId", - table: "Champion", - column: "ClassId"); - - migrationBuilder.CreateIndex( - name: "IX_Champion_ImageBase64", - table: "Champion", - column: "ImageBase64"); - - migrationBuilder.CreateIndex( - name: "IX_ChampionEntitySkillEntity_SkillsName", - table: "ChampionEntitySkillEntity", - column: "SkillsName"); - - migrationBuilder.CreateIndex( - name: "IX_Rune_FamilyId", - table: "Rune", - column: "FamilyId"); - - migrationBuilder.CreateIndex( - name: "IX_Rune_ImageBase64", - table: "Rune", - column: "ImageBase64"); - - migrationBuilder.CreateIndex( - name: "IX_Skill_TypeId", - table: "Skill", - column: "TypeId"); - - migrationBuilder.CreateIndex( - name: "IX_Skin_ChampionSkinName", - table: "Skin", - column: "ChampionSkinName"); - - migrationBuilder.CreateIndex( - name: "IX_Skin_ImageBase64", - table: "Skin", - column: "ImageBase64"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Category"); - - migrationBuilder.DropTable( - name: "ChampionEntitySkillEntity"); - - migrationBuilder.DropTable( - name: "Rune"); - - migrationBuilder.DropTable( - name: "RunePage"); - - migrationBuilder.DropTable( - name: "Skin"); - - migrationBuilder.DropTable( - name: "Skill"); - - migrationBuilder.DropTable( - name: "RuneFamily"); - - migrationBuilder.DropTable( - name: "Champion"); - - migrationBuilder.DropTable( - name: "SkillType"); - - migrationBuilder.DropTable( - name: "ChampionClass"); - - migrationBuilder.DropTable( - name: "Image"); - } - } -} diff --git a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs deleted file mode 100644 index 6b00f17..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs +++ /dev/null @@ -1,288 +0,0 @@ -// -using EntityFrameworkLOL.DBContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - [DbContext(typeof(SQLiteContext))] - partial class SQLiteContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("ChampionEntitySkillEntity", b => - { - b.Property("ChampionsName") - .HasColumnType("TEXT"); - - b.Property("SkillsName") - .HasColumnType("TEXT"); - - b.HasKey("ChampionsName", "SkillsName"); - - b.HasIndex("SkillsName"); - - b.ToTable("ChampionEntitySkillEntity"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.CategoryEntity", b => - { - b.Property("Category") - .HasColumnType("INTEGER"); - - b.HasKey("Category"); - - b.ToTable("Category"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionClassEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Class") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.ToTable("ChampionClass"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ClassId") - .HasColumnType("INTEGER"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageBase64") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.HasIndex("ClassId"); - - b.HasIndex("ImageBase64"); - - b.ToTable("Champion"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ImageEntity", b => - { - b.Property("Base64") - .HasColumnType("TEXT"); - - b.HasKey("Base64"); - - b.ToTable("Image"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("FamilyId") - .HasColumnType("INTEGER"); - - b.Property("ImageBase64") - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.HasIndex("FamilyId"); - - b.HasIndex("ImageBase64"); - - b.ToTable("Rune"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneFamilyEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Family") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.ToTable("RuneFamily"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RunePageEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("RunePage"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("TypeId") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("TypeId"); - - b.ToTable("Skill"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillTypeEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Id"); - - b.ToTable("SkillType"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("ChampionSkinName") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageBase64") - .HasColumnType("TEXT"); - - b.Property("Price") - .HasColumnType("REAL"); - - b.HasKey("Name"); - - b.HasIndex("ChampionSkinName"); - - b.HasIndex("ImageBase64"); - - b.ToTable("Skin"); - }); - - modelBuilder.Entity("ChampionEntitySkillEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", null) - .WithMany() - .HasForeignKey("ChampionsName") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EntityFrameworkLOL.Entities.SkillEntity", null) - .WithMany() - .HasForeignKey("SkillsName") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.ChampionClassEntity", "Class") - .WithMany() - .HasForeignKey("ClassId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageBase64") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Class"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.RuneFamilyEntity", "Family") - .WithMany() - .HasForeignKey("FamilyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageBase64"); - - b.Navigation("Family"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.SkillTypeEntity", "Type") - .WithMany() - .HasForeignKey("TypeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Type"); - }); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => - { - b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "ChampionSkin") - .WithMany() - .HasForeignKey("ChampionSkinName"); - - b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageBase64"); - - b.Navigation("ChampionSkin"); - - b.Navigation("Image"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 67afe5a..ae1d2ac 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{1 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkLOL", "EntityFrameworkLOL\EntityFrameworkLOL.csproj", "{61D807B0-FA1A-439D-9810-9F31A0C47034}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUnitaire", "TestUnitaire\TestUnitaire.csproj", "{D24FBC48-F9C3-45CA-8D51-A851559C307F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUnitaire", "TestUnitaire\TestUnitaire.csproj", "{D24FBC48-F9C3-45CA-8D51-A851559C307F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagersEF", "ManagersEF\ManagersEF.csproj", "{A8685E74-67E4-4382-AF91-38045AC0014B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -61,6 +63,10 @@ Global {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Release|Any CPU.Build.0 = Release|Any CPU + {A8685E74-67E4-4382-AF91-38045AC0014B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8685E74-67E4-4382-AF91-38045AC0014B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8685E74-67E4-4382-AF91-38045AC0014B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8685E74-67E4-4382-AF91-38045AC0014B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/ManagersEF/EFManager.Champions.cs b/Sources/ManagersEF/EFManager.Champions.cs new file mode 100644 index 0000000..8e4b040 --- /dev/null +++ b/Sources/ManagersEF/EFManager.Champions.cs @@ -0,0 +1,136 @@ +using Model; +using Shared; +using System.Data.SqlTypes; +using APILOL.Mapper; + +namespace ManagersEF +{ + public partial class EFManager + { + public class ChampionsManager : IChampionsManager + { + private readonly EFManager parent; + + public ChampionsManager(EFManager parent) + => this.parent = parent; + + public async Task AddItem(Champion? item) + { + await parent.DbContext.Champion.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(Champion? item) + { + parent.DbContext.Champion.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.Champion.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.Champion.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.Champion.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.Champion.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.Champion.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.Champion.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.Champion.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.Champion.Count(); + } + + public async Task GetNbItemsByCharacteristic(string charName) + { + return parent.DbContext.Champion.Where(c => c.Characteristics.Any(ch => ch.Name.Equals(charName))).Count(); + } + + public async Task GetNbItemsByClass(ChampionClass championClass) + { + return parent.DbContext.Champion.Where(c => c.Class.Equals(championClass)) + .Count(); + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.Champion.Where(c => c.Name.Contains(substring)) + .Count(); + } + + public async Task GetNbItemsByRunePage(RunePage? runePage) + { + return parent.DbContext.Champion.Where(c => c.RunePages.Any(rp => rp.Equals(runePage.ToEntity()))).Count(); + + } + + public async Task GetNbItemsBySkill(Skill? skill) + { + return parent.DbContext.Champion.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill.Name))) + .Count(); + } + + public async Task GetNbItemsBySkill(string skill) + { + return parent.DbContext.Champion.Where(c => skill != null && c.Skills.Any(s => s.Name.Equals(skill))) + .Count(); + } + + public async Task UpdateItem(Champion? oldItem, Champion? newItem) + { + parent.DbContext.Champion.Remove(oldItem.ToEntity()); + parent.DbContext.Champion.Add(newItem.ToEntity()); + return newItem; + } + } + } +} \ No newline at end of file diff --git a/Sources/ManagersEF/EFManager.RunePages.cs b/Sources/ManagersEF/EFManager.RunePages.cs new file mode 100644 index 0000000..00e7a12 --- /dev/null +++ b/Sources/ManagersEF/EFManager.RunePages.cs @@ -0,0 +1,92 @@ +using APILOL.Mapper; +using ManagersEF; +using Model; +using System.Data.SqlTypes; +using System.Linq; + +namespace ManagersEF +{ + public partial class EFManager + { + public class RunePagesManager : IRunePagesManager + { + private readonly EFManager parent; + + public RunePagesManager(EFManager parent) + => this.parent = parent; + + public async Task AddItem(RunePage? item) + { + await parent.DbContext.RunePage.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(RunePage? item) + { + parent.DbContext.RunePage.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.RunePage.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.RunePage.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.RunePage.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.RunePage.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.RunePage.Count(); + + } + + public async Task GetNbItemsByChampion(Champion? champion) + { + return parent.DbContext.RunePage.Where(rp => rp.Champions.Any(c => c.Name.Equals(champion.Name))).Count(); + + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.RunePage.Where(rp => rp.Name.Contains(substring)).Count(); + } + + public async Task GetNbItemsByRune(Model.Rune? rune) + { + return parent.DbContext.RunePage.Where(rp => rp.Runes.Any(r => r.Name.Equals(rune.Name))).Count(); + } + + public async Task UpdateItem(RunePage? oldItem, RunePage? newItem) + { + parent.DbContext.RunePage.Remove(oldItem.ToEntity()); + parent.DbContext.RunePage.Add(newItem.ToEntity()); + return newItem; + } + } + } +} \ No newline at end of file diff --git a/Sources/ManagersEF/EFManager.Runes.cs b/Sources/ManagersEF/EFManager.Runes.cs new file mode 100644 index 0000000..025cd1e --- /dev/null +++ b/Sources/ManagersEF/EFManager.Runes.cs @@ -0,0 +1,74 @@ +using APILOL.Mapper; +using Model; +using Shared; + +namespace ManagersEF +{ + public partial class EFManager + { + public class RunesManager : IRunesManager + { + private readonly EFManager parent; + + public RunesManager(EFManager parent) + => this.parent = parent; + public async Task AddItem(Rune? item) + { + await parent.DbContext.Rune.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(Rune? item) + { + parent.DbContext.Rune.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.Rune.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.Rune.GetItemsWithFilterAndOrdering( + r => r.Family.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.Rune.GetItemsWithFilterAndOrdering( + r => r.Name.Contains(substring), + index, count, + orderingPropertyName, descending).Select(r => r.ToModel()); + } + + public async Task GetNbItems() + { + return parent.DbContext.Rune.Count(); + } + + public async Task GetNbItemsByFamily(RuneFamily family) + { + return parent.DbContext.Rune.Where(r => r.Family.Equals(family)).Count(); + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.Rune.Where(r => r.Name.Contains(substring)).Count(); + } + + public async Task UpdateItem(Rune? oldItem, Rune? newItem) + { + parent.DbContext.Rune.Remove(oldItem.ToEntity()); + parent.DbContext.Rune.Add(newItem.ToEntity()); + return newItem; + } + } + } +} \ No newline at end of file diff --git a/Sources/ManagersEF/EFManager.Skins.cs b/Sources/ManagersEF/EFManager.Skins.cs new file mode 100644 index 0000000..1810631 --- /dev/null +++ b/Sources/ManagersEF/EFManager.Skins.cs @@ -0,0 +1,77 @@ +using APILOL.Mapper; +using Model; +using System.Data.SqlTypes; + +namespace ManagersEF +{ + public partial class EFManager + { + public class SkinsManager : ISkinsManager + { + private readonly EFManager parent; + + public SkinsManager(EFManager parent) + => this.parent = parent; + + public async Task AddItem(Skin? item) + { + await parent.DbContext.Skin.AddAsync(item.ToEntity()); + return item; + } + + public async Task DeleteItem(Skin? item) + { + parent.DbContext.Skin.Remove(item.ToEntity()); + return true; + } + + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return parent.DbContext.Skin.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.Skin.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.Skin.GetItemsWithFilterAndOrdering( + s => s.Name.Contains(substring), + index, count, + orderingPropertyName, descending).Select(s => s.ToModel()); + } + + public async Task GetNbItems() + { + return parent.DbContext.Skin.Count(); + } + + public async Task GetNbItemsByChampion(Champion? champion) + { + return parent.DbContext.Skin.Where(s => s.Champion.Name.Equals(champion.Name)) + .Count(); + } + + public async Task GetNbItemsByName(string substring) + { + return parent.DbContext.Skin.Where(s => s.Name.Contains(substring)) + .Count(); + } + + public async Task UpdateItem(Skin? oldItem, Skin? newItem) + { + parent.DbContext.Skin.Remove(oldItem.ToEntity()); + parent.DbContext.Skin.Add(newItem.ToEntity()); + return newItem; + } + } + } +} \ No newline at end of file diff --git a/Sources/ManagersEF/EFManager.cs b/Sources/ManagersEF/EFManager.cs new file mode 100644 index 0000000..181bf97 --- /dev/null +++ b/Sources/ManagersEF/EFManager.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore; +using Model; +using EntityFrameworkLOL.DBContexts; + +namespace ManagersEF +{ + public partial class EFManager : IDataManager + { + + public EFManager(SQLiteContext dbContext) + { + DbContext = dbContext; + ChampionsMgr = new ChampionsManager(this); + SkinsMgr = new SkinsManager(this); + RunesMgr = new RunesManager(this); + RunePagesMgr = new RunePagesManager(this); + } + protected SQLiteContext 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/Sources/ManagersEF/Extensions.cs b/Sources/ManagersEF/Extensions.cs new file mode 100644 index 0000000..c178ccf --- /dev/null +++ b/Sources/ManagersEF/Extensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ManagersEF +{ + 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); + } + } +} \ No newline at end of file diff --git a/Sources/ManagersEF/ManagersEF.csproj b/Sources/ManagersEF/ManagersEF.csproj new file mode 100644 index 0000000..2b6d57c --- /dev/null +++ b/Sources/ManagersEF/ManagersEF.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + + + + + + + + +