From 6f6fc4c5e0fc142e8be6ca58d7d67cdd7e37a326 Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:47:25 +0100 Subject: [PATCH 1/5] Implement add --- Sources/EF_UT/EFDataManagerChampionTest.cs | 26 ++++ .../EntityFramework/EntityFramework.csproj | 11 +- .../Manager/EFDataManager.Champions.cs | 124 ++++++++++++++++++ .../EntityFramework/Manager/EFDataManager.cs | 24 ++++ .../EntityFramework/Mapper/ChampionMapper.cs | 1 + Sources/EntityFramework/champion.db-shm | Bin 0 -> 32768 bytes Sources/EntityFramework/champion.db-wal | 0 7 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 Sources/EF_UT/EFDataManagerChampionTest.cs create mode 100644 Sources/EntityFramework/Manager/EFDataManager.Champions.cs create mode 100644 Sources/EntityFramework/Manager/EFDataManager.cs create mode 100644 Sources/EntityFramework/champion.db-shm create mode 100644 Sources/EntityFramework/champion.db-wal diff --git a/Sources/EF_UT/EFDataManagerChampionTest.cs b/Sources/EF_UT/EFDataManagerChampionTest.cs new file mode 100644 index 0000000..843a4e5 --- /dev/null +++ b/Sources/EF_UT/EFDataManagerChampionTest.cs @@ -0,0 +1,26 @@ +using EntityFramework; +using EntityFramework.Manager; +using FluentAssertions; +using Microsoft.EntityFrameworkCore; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EF_UT +{ + [TestClass] + public class EFDataManagerChampionTest + { + [TestMethod] + public void Add_ValidChampion_Added() + { + IDataManager dataManager = new EFDataManager(); + IChampionsManager championsManager = dataManager.ChampionsMgr; + + var champ = championsManager.AddItem(new Champion("test")); + } + } +} diff --git a/Sources/EntityFramework/EntityFramework.csproj b/Sources/EntityFramework/EntityFramework.csproj index 2d1f7fc..358fe36 100644 --- a/Sources/EntityFramework/EntityFramework.csproj +++ b/Sources/EntityFramework/EntityFramework.csproj @@ -1,4 +1,4 @@ - + Exe @@ -8,6 +8,14 @@ $(MSBuildProjectDirectory) + + + + + + + + @@ -18,6 +26,7 @@ + diff --git a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs new file mode 100644 index 0000000..8dd70b4 --- /dev/null +++ b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs @@ -0,0 +1,124 @@ +using EntityFramework.Mapper; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace EntityFramework.Manager +{ + public partial class EFDataManager + { + public class ChampionsManager : IChampionsManager + { + private readonly EFDataManager parent; + + public ChampionsManager(EFDataManager parent) + { + this.parent = parent; + } + + public async Task AddItem(Champion? item) + { + using(var context = new LoLDBContextWithStub()) + { + if (item != null) + { + context.Add(item.ToEntity()); + return item; + } + else + { + throw new Exception(); + } + } + } + + public Task DeleteItem(Champion? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByClass(Model.ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + using (var context = new LoLDBContextWithStub()) + { + IEnumerable champ = context.Champions.Where(c => c.Name.Contains(substring)); + return champ. + } + } + + public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByCharacteristic(string charName) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByClass(Model.ChampionClass championClass) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByName(string substring) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsByRunePage(RunePage? runePage) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsBySkill(Skill? skill) + { + throw new NotImplementedException(); + } + + public Task GetNbItemsBySkill(string skill) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Champion? oldItem, Champion? newItem) + { + throw new NotImplementedException(); + } + } + } +} diff --git a/Sources/EntityFramework/Manager/EFDataManager.cs b/Sources/EntityFramework/Manager/EFDataManager.cs new file mode 100644 index 0000000..9465809 --- /dev/null +++ b/Sources/EntityFramework/Manager/EFDataManager.cs @@ -0,0 +1,24 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework.Manager +{ + public partial class EFDataManager : IDataManager + { + public EFDataManager() { + ChampionsMgr = new ChampionsManager(this); + } + public IChampionsManager ChampionsMgr { get; } + + public ISkinsManager SkinsMgr { get; } + + public IRunesManager RunesMgr { get; } + + public IRunePagesManager RunePagesMgr { get; } + + } +} diff --git a/Sources/EntityFramework/Mapper/ChampionMapper.cs b/Sources/EntityFramework/Mapper/ChampionMapper.cs index 862264d..09b48c3 100644 --- a/Sources/EntityFramework/Mapper/ChampionMapper.cs +++ b/Sources/EntityFramework/Mapper/ChampionMapper.cs @@ -12,5 +12,6 @@ namespace EntityFramework.Mapper public static ChampionEntity ToEntity(this Champion champion) { return new ChampionEntity(champion.Name, champion.Bio, champion.Icon); } + } } diff --git a/Sources/EntityFramework/champion.db-shm b/Sources/EntityFramework/champion.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10 GIT binary patch literal 32768 zcmeIuAr62r3 Date: Wed, 15 Mar 2023 16:50:27 +0100 Subject: [PATCH 2/5] add --- Sources/EntityFramework/LargeImageEntity.cs | 22 +++++ .../20230312170120_stubMig.Designer.cs | 83 ------------------ .../Migrations/20230312170120_stubMig.cs | 49 ----------- .../LoLDBContextWithStubModelSnapshot.cs | 80 ----------------- Sources/EntityFramework/SkinEntity.cs | 79 +++++++++++++++++ Sources/EntityFramework/StubbedContext.cs | 44 ++++++++++ Sources/EntityFramework/champion.db | Bin 20480 -> 0 bytes Sources/EntityFramework/champion.db-shm | Bin 32768 -> 0 bytes Sources/EntityFramework/champion.db-wal | 0 9 files changed, 145 insertions(+), 212 deletions(-) create mode 100644 Sources/EntityFramework/LargeImageEntity.cs delete mode 100644 Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs delete mode 100644 Sources/EntityFramework/Migrations/20230312170120_stubMig.cs delete mode 100644 Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs create mode 100644 Sources/EntityFramework/SkinEntity.cs create mode 100644 Sources/EntityFramework/StubbedContext.cs delete mode 100644 Sources/EntityFramework/champion.db delete mode 100644 Sources/EntityFramework/champion.db-shm delete mode 100644 Sources/EntityFramework/champion.db-wal diff --git a/Sources/EntityFramework/LargeImageEntity.cs b/Sources/EntityFramework/LargeImageEntity.cs new file mode 100644 index 0000000..b925a83 --- /dev/null +++ b/Sources/EntityFramework/LargeImageEntity.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + + public class LargeImageEntity + { + public int Id { get; set; } + public string Base64 { get; set; } + + //public LargeImageEntity(string base64) + //{ + // Base64 = base64; + //} + } +} diff --git a/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs b/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs deleted file mode 100644 index 2b24874..0000000 --- a/Sources/EntityFramework/Migrations/20230312170120_stubMig.Designer.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDBContextWithStub))] - [Migration("20230312170120_stubMig")] - partial class stubMig - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Name") - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("Champion", (string)null); - - b.HasData( - new - { - Name = "Akali", - Bio = "", - Icon = "" - }, - new - { - Name = "Aatrox", - Bio = "", - Icon = "" - }, - new - { - Name = "Ahri", - Bio = "", - Icon = "" - }, - new - { - Name = "Akshan", - Bio = "", - Icon = "" - }, - new - { - Name = "Bard", - Bio = "", - Icon = "" - }, - new - { - Name = "Alistar", - Bio = "", - Icon = "" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs b/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs deleted file mode 100644 index 3323fa4..0000000 --- a/Sources/EntityFramework/Migrations/20230312170120_stubMig.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace EntityFramework.Migrations -{ - /// - public partial class stubMig : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champion", - columns: table => new - { - Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), - Bio = table.Column(type: "string", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champion", x => x.Name); - }); - - migrationBuilder.InsertData( - table: "Champion", - columns: new[] { "Name", "Bio", "Icon" }, - values: new object[,] - { - { "Aatrox", "", "" }, - { "Ahri", "", "" }, - { "Akali", "", "" }, - { "Akshan", "", "" }, - { "Alistar", "", "" }, - { "Bard", "", "" } - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Champion"); - } - } -} diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs deleted file mode 100644 index ba61c51..0000000 --- a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -using EntityFramework; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFramework.Migrations -{ - [DbContext(typeof(LoLDBContextWithStub))] - partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFramework.ChampionEntity", b => - { - b.Property("Name") - .HasMaxLength(50) - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("string") - .HasColumnName("Bio"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("Champion", (string)null); - - b.HasData( - new - { - Name = "Akali", - Bio = "", - Icon = "" - }, - new - { - Name = "Aatrox", - Bio = "", - Icon = "" - }, - new - { - Name = "Ahri", - Bio = "", - Icon = "" - }, - new - { - Name = "Akshan", - Bio = "", - Icon = "" - }, - new - { - Name = "Bard", - Bio = "", - Icon = "" - }, - new - { - Name = "Alistar", - Bio = "", - Icon = "" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFramework/SkinEntity.cs b/Sources/EntityFramework/SkinEntity.cs new file mode 100644 index 0000000..e9650b3 --- /dev/null +++ b/Sources/EntityFramework/SkinEntity.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + public class SkinEntity //ONE TO MANY + { + + public string? Name { get; set; } + + public string? Description { get; set; } + + //public string Name + //{ + // get => name; + // private init + // { + // if (string.IsNullOrWhiteSpace(value)) + // { + // throw new ArgumentException("A skin must have a name"); + // } + // name = value; + // } + //} + //private readonly string name = null!; + + //public string Description + //{ + // get => description; + // set + // { + // if (string.IsNullOrWhiteSpace(value)) + // { + // description = ""; + // return; + // } + // description = value; + // } + //} + //private string description = ""; + + public string Icon { get; set; } = ""; + + + //public LargeImageEntity Image { get; set; } + public string? Image { get; set; } + + + public float Price { get; set; } + public ChampionEntity Champion { get; set; } + + + //public ChampionEntity Champion + //{ + // get => champion; + // private init + // { + // if (value == null) + // throw new ArgumentNullException("A skill can't have a null champion"); + // champion = value; + // } + //} + //private readonly ChampionEntity champion = null!; + + //public SkinEntity(string name, ChampionEntity champion, float price = 0.0f, string icon = "", string image = "", string description = "") + //{ + // Name = name; + // Champion = champion; + // //Champion.AddSkin(this); + // Price = price; + // Icon = icon; + // Image = new LargeImageEntity(image); + // Description = description; + //} + } +} diff --git a/Sources/EntityFramework/StubbedContext.cs b/Sources/EntityFramework/StubbedContext.cs new file mode 100644 index 0000000..833f0c7 --- /dev/null +++ b/Sources/EntityFramework/StubbedContext.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + public class StubbedContext : LoLDbContext + { + //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + //{ + // optionsBuilder.EnableSensitiveDataLogging(); + //} + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + ChampionEntity corichard = new ChampionEntity {Name="Corichard", Bio="biobiobiobio", Icon="/a/a/a/a"}; + ChampionEntity pintrand = new ChampionEntity {Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png" }; + + //ChampionEntity corichard = new ChampionEntity() { Name = "Corichard", Bio = "biobiobiobio", Icon = "/a/a/a/a", Image = new LargeImageEntity { Base64 = "base" } }; + //ChampionEntity pintrand = new ChampionEntity { Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png", Image = new LargeImageEntity { Base64 = "base" } }; + + modelBuilder.Entity().HasData(corichard, pintrand); + + modelBuilder.Entity().HasData(new { Name = "aaaa", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon="/Icon.png", Price=10.0f }, + new { Name = "skin", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "bo", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "Joulie", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "Radiance", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "void", ChampionEntityForeignKey = "Corichard", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "Radiance", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "void", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "DarkTheme", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "gold", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f }, + new { Name = "ruby", ChampionEntityForeignKey = "Pintrand", Description = "So What", Icon = "/Icon.png", Price = 10.0f } + ); + } + + } +} diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db deleted file mode 100644 index b0ff12d7b320d5866aecbae454397eb8c1f38820..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeI(J#W)M7zgn4OWeejdn}a|s-ROQkWd;YL(~l?G9qf4gw&vRK$hF2jYSfJ?MP*8 zzX>0JZ@`Ac!~_c)NJtDws0%`joI{;LDN5P!P_H$UPVh8bf#d%=0J7S#I{@UCf!AL zTT>a2V%r@Lip;k5Y}W4Z@~G8fjZS;l?wQTD&5GS^=klU%ueoFP_Sv?zfA`}0y5|>J z7zN(scs@b$Tl3JLEX=K`cQ$23ZxjULP5OhA@cD?ptvc>B@@MV&Vvdn4n>pPRR`gm; zIP1)|=s4E>9q%}BBfih@ffq)8@FKNS{CD%IV=g7;b2j@6H@yh5WTF(EZs7N)htcCf z5b~Q{n3h{KMMZy7TV|2Ej$@>DOZTi$FgUejp$K0SG_<0uX=z1Rwwb2tWV= z5V)oSw*+ZRuaqm*a@D99wX#tuJ7F|E;OUE6sa&e4d|v|nO89|*00bZa0SG_<0uX=z z1Rwwb2teRk3*@D(TzV29{{FAf*M$C{-{>d$fxhJp1Oy-e0SG_<0uX=z1Rwwb2tWV= zS4JSK$m^O`cZ2?FM&8ggbHxAM;0CHJ=Xv94ICLjDN!H`KJMyw(JlY%vo+``+xKZGr z#NYoF`i9V-^gI1RKhk%+fq(!6AOHafKmY;|fB*y_009U<;Hn8^rF9`r0w}A}hH#Ms g$f#0Y_>%&VbCS-hJOd!bBjW^sn3M83bN2rK8;u#~Z2$lO diff --git a/Sources/EntityFramework/champion.db-shm b/Sources/EntityFramework/champion.db-shm deleted file mode 100644 index fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIuAr62r3 Date: Wed, 15 Mar 2023 17:05:35 +0100 Subject: [PATCH 3/5] fix :bug: --- Sources/EntityFramework/Manager/EFDataManager.Champions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs index bb87e6f..9bfd098 100644 --- a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs +++ b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs @@ -58,10 +58,11 @@ namespace EntityFramework.Manager public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { + throw new NotImplementedException(); using (var context = new LoLDBContextWithStub()) { IEnumerable champ = context.Champions.Where(c => c.Name.Contains(substring)); - return champ.ToList().Where(l => l.toCh) + //return champ.ToList().Where(l => l.toCh) } } -- 2.36.3 From b41894300de911adc330e3aac0ffaeea0835351a Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Sun, 19 Mar 2023 23:55:09 +0100 Subject: [PATCH 4/5] Problem not fix --- Sources/EntityFramework/LoLDbContext.cs | 2 +- .../Manager/EFDataManager.Champions.cs | 10 +- .../EntityFramework/Mapper/ChampionMapper.cs | 5 + .../20230319224555_myMig.Designer.cs | 175 ++++++++++++++++++ .../Migrations/20230319224555_myMig.cs | 122 ++++++++++++ .../LoLDBContextWithStubModelSnapshot.cs | 172 +++++++++++++++++ Sources/EntityFramework/champion.db | Bin 0 -> 53248 bytes 7 files changed, 481 insertions(+), 5 deletions(-) create mode 100644 Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs create mode 100644 Sources/EntityFramework/Migrations/20230319224555_myMig.cs create mode 100644 Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs create mode 100644 Sources/EntityFramework/champion.db diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index af9be3b..003ff03 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -35,7 +35,7 @@ namespace EntityFramework protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasKey(entity => entity.Name); - modelBuilder.Entity().ToTable("Champion"); + modelBuilder.Entity().ToTable("Champions"); //modelBuilder.Entity().Property(entity => entity.Id) // .ValueGeneratedOnAdd(); diff --git a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs index 9bfd098..c0ecda6 100644 --- a/Sources/EntityFramework/Manager/EFDataManager.Champions.cs +++ b/Sources/EntityFramework/Manager/EFDataManager.Champions.cs @@ -56,13 +56,15 @@ namespace EntityFramework.Manager throw new NotImplementedException(); } - public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); using (var context = new LoLDBContextWithStub()) { - IEnumerable champ = context.Champions.Where(c => c.Name.Contains(substring)); - //return champ.ToList().Where(l => l.toCh) + + var champ = context.Champions.Where(c => c.Name.Contains(substring)).AsEnumerable(); + return champ.Select(c => c.ToChampion()).ToList(); + + } } diff --git a/Sources/EntityFramework/Mapper/ChampionMapper.cs b/Sources/EntityFramework/Mapper/ChampionMapper.cs index 2a3e9f4..da146b2 100644 --- a/Sources/EntityFramework/Mapper/ChampionMapper.cs +++ b/Sources/EntityFramework/Mapper/ChampionMapper.cs @@ -13,5 +13,10 @@ namespace EntityFramework.Mapper return new ChampionEntity { Name = champion.Name, Bio = champion.Bio, Icon = champion.Icon }; } + public static Champion ToChampion(this ChampionEntity champion) + { + return new Champion(champion.Name,bio: champion.Bio,icon: champion.Icon); + } + } } diff --git a/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs b/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs new file mode 100644 index 0000000..2a90b9d --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs @@ -0,0 +1,175 @@ +// +using EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramework.Migrations +{ + [DbContext(typeof(LoLDBContextWithStub))] + [Migration("20230319224555_myMig")] + partial class myMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("string") + .HasColumnName("Bio"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champions", (string)null); + + b.HasData( + new + { + Name = "Akali", + Bio = "", + Icon = "" + }, + new + { + Name = "Aatrox", + Bio = "", + Icon = "" + }, + new + { + Name = "Ahri", + Bio = "", + Icon = "" + }, + new + { + Name = "Akshan", + Bio = "", + Icon = "" + }, + new + { + Name = "Bard", + Bio = "", + Icon = "" + }, + new + { + Name = "Alistar", + Bio = "", + Icon = "" + }); + }); + + modelBuilder.Entity("EntityFramework.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Image"); + }); + + modelBuilder.Entity("EntityFramework.SkillEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionEntityName") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityName"); + + b.ToTable("SkillEntity"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ChampionEntityForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityForeignKey"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("EntityFramework.SkillEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", null) + .WithMany("Skills") + .HasForeignKey("ChampionEntityName"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", "Champion") + .WithMany("skins") + .HasForeignKey("ChampionEntityForeignKey"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Navigation("Skills"); + + b.Navigation("skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramework/Migrations/20230319224555_myMig.cs b/Sources/EntityFramework/Migrations/20230319224555_myMig.cs new file mode 100644 index 0000000..0e61c80 --- /dev/null +++ b/Sources/EntityFramework/Migrations/20230319224555_myMig.cs @@ -0,0 +1,122 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace EntityFramework.Migrations +{ + /// + public partial class myMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 50, nullable: false), + Bio = table.Column(type: "string", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Image = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "Image", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Image", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SkillEntity", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + ChampionEntityName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_SkillEntity", x => x.Name); + table.ForeignKey( + name: "FK_SkillEntity_Champions_ChampionEntityName", + column: x => x.ChampionEntityName, + principalTable: "Champions", + principalColumn: "Name"); + }); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: true), + Icon = table.Column(type: "TEXT", nullable: false), + Image = table.Column(type: "TEXT", nullable: true), + Price = table.Column(type: "REAL", nullable: false), + ChampionEntityForeignKey = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Name); + table.ForeignKey( + name: "FK_Skins_Champions_ChampionEntityForeignKey", + column: x => x.ChampionEntityForeignKey, + principalTable: "Champions", + principalColumn: "Name"); + }); + + migrationBuilder.InsertData( + table: "Champions", + columns: new[] { "Name", "Bio", "Icon", "Image" }, + values: new object[,] + { + { "Aatrox", "", "", null }, + { "Ahri", "", "", null }, + { "Akali", "", "", null }, + { "Akshan", "", "", null }, + { "Alistar", "", "", null }, + { "Bard", "", "", null } + }); + + migrationBuilder.CreateIndex( + name: "IX_SkillEntity_ChampionEntityName", + table: "SkillEntity", + column: "ChampionEntityName"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ChampionEntityForeignKey", + table: "Skins", + column: "ChampionEntityForeignKey"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Image"); + + migrationBuilder.DropTable( + name: "SkillEntity"); + + migrationBuilder.DropTable( + name: "Skins"); + + migrationBuilder.DropTable( + name: "Champions"); + } + } +} diff --git a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs new file mode 100644 index 0000000..e00a86a --- /dev/null +++ b/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs @@ -0,0 +1,172 @@ +// +using EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFramework.Migrations +{ + [DbContext(typeof(LoLDBContextWithStub))] + partial class LoLDBContextWithStubModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("string") + .HasColumnName("Bio"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("Champions", (string)null); + + b.HasData( + new + { + Name = "Akali", + Bio = "", + Icon = "" + }, + new + { + Name = "Aatrox", + Bio = "", + Icon = "" + }, + new + { + Name = "Ahri", + Bio = "", + Icon = "" + }, + new + { + Name = "Akshan", + Bio = "", + Icon = "" + }, + new + { + Name = "Bard", + Bio = "", + Icon = "" + }, + new + { + Name = "Alistar", + Bio = "", + Icon = "" + }); + }); + + modelBuilder.Entity("EntityFramework.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Image"); + }); + + modelBuilder.Entity("EntityFramework.SkillEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionEntityName") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityName"); + + b.ToTable("SkillEntity"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.Property("Name") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("ChampionEntityForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Image") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityForeignKey"); + + b.ToTable("Skins"); + }); + + modelBuilder.Entity("EntityFramework.SkillEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", null) + .WithMany("Skills") + .HasForeignKey("ChampionEntityName"); + }); + + modelBuilder.Entity("EntityFramework.SkinEntity", b => + { + b.HasOne("EntityFramework.ChampionEntity", "Champion") + .WithMany("skins") + .HasForeignKey("ChampionEntityForeignKey"); + + b.Navigation("Champion"); + }); + + modelBuilder.Entity("EntityFramework.ChampionEntity", b => + { + b.Navigation("Skills"); + + b.Navigation("skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db new file mode 100644 index 0000000000000000000000000000000000000000..d6b07a7f3f047be19725f261f5ceb2230711d230 GIT binary patch literal 53248 zcmeI)&2QUu9LI4xX`YjLNKB>-RLi}r+En#nS;b+3v~x$)F6q(?wFeZL)U;O9q_b18 z9#ho6gTG)`?uaWAf)fW$z+o2-2nliIXD7}>lN2W9kfFELw0`>i{PpW&Td~u2_vyCX zw6xC~&WYL7R;8O#C?tKPX_6#`#496S!4MN8Gr@%TDff+!8x2W|m3K4B-%>hWm2Ui~ zyv+P?^)2h%Uz*t{8M(5d2;v^MlpYYV9Jf)KoA}EYW4KG(D=OVBv_S-I{`RhAZ>7pf7xxPQ+AIl`p?& znxECYP1ariTe7poa&CRw=@9aqOy?FJjy7 zmJ_rY8^_R=`|IEA)Ze8Yf6VCGX0c@C9~Zn`yf%MP;HFVB3LD0*);&yIFPU~0ndHJk zGO9jQWywEW-RCv&2DxIMH5>kP=ipuT^GRJC$71UIynOk7kX(>;-*FQkN-1I?$3|%=f)RON33f1~{)4M`U<}6-lr%P^c1PF6(}w>K!DQo6H9vn% zFx_Ijc!G(`}2As=MRSSxq8NSn)KzX<(`#``GV;AiBTvAr_{RXS`Y3A=V2#Gaqzab z!ZCGjPQI}G(t=Rk?#RqwiQW0VGW(++b6x3c)mLe^HoKu~Zqu>rheOBVYg}2x-Ym~V zRby^k;@v7L%iYmPYfp};YisgF(FdqhjLj$Zp<{YiI`?DSZ8n_qkuyVsFeBILA$9xo zLcR7HJf@=&ZaYrn;H=vG#B$ue%W^N1Zx;9Q@kM#H+$3ayYB5EUm0AtuBACvT{G0%~np%#p8>$#ihlS zq}VT6c_oQ21_Tg5009ILKmY**5I_I{1Q2+`1=MghG3p_J_xXQR`C3x`R9-1RE8i>M zhzSM+5I_I{1Q0*~0R#|0009ILm;!-BG;%AGk=9M;ARUR^7NfbE_{#>X?}3-9y)sPe6({H6S^{Hpwi3g4DH&jBLI@T}Z^3NVuht723<0|0^I*kXD(EQ00IagfB*srAbfB*srAb Date: Thu, 23 Mar 2023 00:39:08 +0100 Subject: [PATCH 5/5] Liaison de l'API avec l'EF --- Sources/API_LoL/API_LoL.csproj | 1 + .../Controllers/ChampionsController.cs | 5 +- Sources/API_LoL/Program.cs | 14 +- Sources/API_LoL/champion.db | Bin 0 -> 45056 bytes Sources/API_LoL/champion.db-shm | Bin 0 -> 32768 bytes Sources/API_LoL/champion.db-wal | 0 Sources/EF_UT/EFDataManagerChampionTest.cs | 13 ++ .../Manager/EFDataManager.Champions.cs | 46 ++++++- .../Manager/EFDataManager.Skins.cs | 85 +++++++++++++ .../EntityFramework/Manager/EFDataManager.cs | 1 + Sources/EntityFramework/Mapper/SkinMapper.cs | 24 ++++ Sources/EntityFramework/Program.cs | 120 ++++++++++-------- 12 files changed, 241 insertions(+), 68 deletions(-) create mode 100644 Sources/API_LoL/champion.db create mode 100644 Sources/API_LoL/champion.db-shm create mode 100644 Sources/API_LoL/champion.db-wal create mode 100644 Sources/EntityFramework/Manager/EFDataManager.Skins.cs create mode 100644 Sources/EntityFramework/Mapper/SkinMapper.cs diff --git a/Sources/API_LoL/API_LoL.csproj b/Sources/API_LoL/API_LoL.csproj index a8c4de7..db2c1c8 100644 --- a/Sources/API_LoL/API_LoL.csproj +++ b/Sources/API_LoL/API_LoL.csproj @@ -17,6 +17,7 @@ + diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 1b2b021..1a077b8 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -92,9 +92,10 @@ namespace API_LoL.Controllers var list = await ChampionsManager.GetItemsByName(name, 0, 1); if (list.Count() == 1) { - var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First())); - if (skins.Count() != 0) + var nb = await SkinsManager.GetNbItemsByChampion(list.First()); + if (nb != 0) { + var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, nb); return Ok(skins.Select(skin => skin?.ToDTO())); } else { return NoContent(); } diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index c192eac..7c535a4 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -1,4 +1,6 @@ using API_LoL; +using EntityFramework; +using EntityFramework.Manager; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Versioning; using Model; @@ -37,13 +39,19 @@ builder.Services.AddControllers(); -builder.Services.AddScoped(); - - +//builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddDbContext(); var app = builder.Build(); +using(var scope = app.Services.CreateScope()) +{ + var context = scope.ServiceProvider.GetService(); + context.Database.EnsureCreated(); +} + var apiVersionDescriptionProvider = app.Services.GetRequiredService(); diff --git a/Sources/API_LoL/champion.db b/Sources/API_LoL/champion.db new file mode 100644 index 0000000000000000000000000000000000000000..bea5ebdc870b51ff37a7cbd336d99b26a24da2d7 GIT binary patch literal 45056 zcmeI(y>H`m9LI4x4^HDWH4GI*x3E@YU3JU9sNb%BqUvHL69NbzfB*srAh4_ggOXa%8@fDr==mq^3;VEraPIj*d*{r# zxb(Wd<@de*)o!=vdZ+%LdlhXh?KG`w%QEcxBkRyG|F@B8H0p*KH8qWU=AwO@mBHIZ zQO)LLHJ#3|h^dnQT?()s$?U(=@FqdChEP;StQr*QIbc6)vmV;bAN9rZ5sPc`$@HV zWb9c-58}p;+~Bz9UG_x)X1ov4KG|v?k5(sGhE3*(qM z@_7Bbas4Un;xS_yyN#x0Kdy&eyfJ@K;I7rQ>O0nfkq(m}OlFuxS*=u76#bztOVMx* zo^`}!MB91Z??%h<;N6PyDPEuF3;O1!{PMjdxg_hcaih$nn7l|F_O-GcwVRV@>*`YY zi{!1xR&yqTIeAY7I~mgW;2I5#*?5wY7KSw3(M|CT;a?$`j}%3>H*W|gEhda7St#u1 z6#f2v`6!Ag&NFbIJ$L;G z4bqv+WQpneQJLe>FL+-WYc*DBTASB3jiBH2{L`6n_!{plqBmO^MYlEb009ILKmY**5I_I{1Q2)w1d2-jPPr^? zJH3F;cJ|Julqt3y-~Cu zB<*kQPwjW@SM4XUz=Qw-2q1s}0tg_000IagfB*t-n!rl-jvU?zP)gama(o{kuV&Zf z;az}SF{_JNaStFHzB0T6kSS)@i`D4*Km7h*{OF$v0R#|0009ILKmY**5I_I{1a7ea z*Z;RTT)Kt;0tg_000IagfB*srAb>zD!1X^v0RaRMKmY**5I_I{1Q0*~f!i+-{{KI} z|G)h?(?bLhKmY**5I_I{1Q0*~f#nw9`~T(6pWY*Y00IagfB*srAbX literal 0 HcmV?d00001 diff --git a/Sources/API_LoL/champion.db-shm b/Sources/API_LoL/champion.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10 GIT binary patch literal 32768 zcmeIuAr62r3> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + using(var context = new LoLDBContextWithStub() ) + { + var champ = context.Champions.ToArray(); + if (descending == false) + { + return champ.ToList().Skip(index * count).Take(count).Select(c => c.ToChampion()).OrderBy(c => c.Name); + } + else + { + return champ.ToList().Skip(index * count).Take(count).Select(c => c.ToChampion()).OrderByDescending(c => c.Name); + } + } } public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) @@ -60,11 +71,20 @@ namespace EntityFramework.Manager { using (var context = new LoLDBContextWithStub()) { - var champ = context.Champions.Where(c => c.Name.Contains(substring)).AsEnumerable(); - return champ.Select(c => c.ToChampion()).ToList(); + if (descending == false) + { + return champ.Select(c => c.ToChampion()).ToList().Skip(index * count).Take(count).OrderBy(c=> c.Name); + + } + else + { + return champ.Select(c => c.ToChampion()).ToList().Skip(index*count).Take(count).OrderByDescending(c => c.Name); + + } + + - } } @@ -78,9 +98,21 @@ namespace EntityFramework.Manager throw new NotImplementedException(); } - public Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) + public async Task> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + using(var context = new LoLDBContextWithStub()) + { + var champ = context.Champions.Where(c => c.Skills.Any(c => c.Name.Contains(skill))); + if (descending.Equals(false)) + { + return champ.Select(c=> c.ToChampion()).ToList().Skip(index * count).Take(count).OrderBy(c => c.Name); + + } + else + { + return champ.Select(c => c.ToChampion()).ToList().Skip(index * count).Take(count).OrderByDescending(c => c.Name); + } + } } public Task GetNbItems() diff --git a/Sources/EntityFramework/Manager/EFDataManager.Skins.cs b/Sources/EntityFramework/Manager/EFDataManager.Skins.cs new file mode 100644 index 0000000..bed5678 --- /dev/null +++ b/Sources/EntityFramework/Manager/EFDataManager.Skins.cs @@ -0,0 +1,85 @@ +using EntityFramework.Mapper; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework.Manager +{ + public partial class EFDataManager + { + public class SkinsManager : ISkinsManager + { + private readonly EFDataManager parent; + + public SkinsManager(EFDataManager parent) + { + this.parent = parent; + } + + public Task AddItem(Skin? item) + { + throw new NotImplementedException(); + } + + public Task DeleteItem(Skin? item) + { + throw new NotImplementedException(); + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public async Task> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + using (var context = new LoLDBContextWithStub()) + { + var skins = context.Skins.Where(c => c.Champion.Equals(champion)).ToList(); + + if (descending == false) + { + return skins.Select(c => c.ToSkin()).ToList().Skip(index * count).Take(count).OrderBy(c => c.Name); + + } + else + { + return skins.Select(c => c.ToSkin()).ToList().Skip(index * count).Take(count).OrderByDescending(c => c.Name); + + } + } + } + + public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task GetNbItems() + { + throw new NotImplementedException(); + } + + public async Task GetNbItemsByChampion(Champion? champion) + { + using(var context = new LoLDBContextWithStub()) + { + return context.Skins.Where(c => c.Champion.Equals(champion.ToEntity())).Count(); + } + } + + public Task GetNbItemsByName(string substring) + { + throw new NotImplementedException(); + } + + public Task UpdateItem(Skin? oldItem, Skin? newItem) + { + throw new NotImplementedException(); + } + } + } +} diff --git a/Sources/EntityFramework/Manager/EFDataManager.cs b/Sources/EntityFramework/Manager/EFDataManager.cs index 9465809..5c5d677 100644 --- a/Sources/EntityFramework/Manager/EFDataManager.cs +++ b/Sources/EntityFramework/Manager/EFDataManager.cs @@ -11,6 +11,7 @@ namespace EntityFramework.Manager { public EFDataManager() { ChampionsMgr = new ChampionsManager(this); + SkinsMgr = new SkinsManager(this); } public IChampionsManager ChampionsMgr { get; } diff --git a/Sources/EntityFramework/Mapper/SkinMapper.cs b/Sources/EntityFramework/Mapper/SkinMapper.cs new file mode 100644 index 0000000..3ce09ff --- /dev/null +++ b/Sources/EntityFramework/Mapper/SkinMapper.cs @@ -0,0 +1,24 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework.Mapper +{ + public static class SkinMapper + { + public static SkinEntity ToEntity(this Skin skin) + { + return new SkinEntity { Champion = skin.Champion.ToEntity(), Description = skin.Description, Icon = skin.Icon, Image = skin.Image.Base64, Name = skin.Name, Price = skin.Price }; + } + + public static Skin ToSkin(this SkinEntity entity) + { + return new Skin(entity.Name,entity.Champion.ToChampion(),price: entity.Price,icon: entity.Icon, image: entity.Image,description: entity.Description); + } + + + } +} diff --git a/Sources/EntityFramework/Program.cs b/Sources/EntityFramework/Program.cs index 818faa5..8c67f3f 100644 --- a/Sources/EntityFramework/Program.cs +++ b/Sources/EntityFramework/Program.cs @@ -1,78 +1,86 @@ // See https://aka.ms/new-console-template for more information using EntityFramework; +using EntityFramework.Manager; using Microsoft.EntityFrameworkCore; +using Model; -using ( var context = new LoLDbContext()) -{ - //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } ); - context.SaveChanges(); +IDataManager dataManager = new EFDataManager(); +IChampionsManager championsManager = dataManager.ChampionsMgr; +IEnumerable champions = await championsManager.GetItemsByName("A", 0, 1); +Console.WriteLine(champions.First().Name); - ChampionEntity champ = context.Find("Akali"); - if( champ != null) - { - Console - .WriteLine(champ.ToString()); +//using ( var context = new LoLDbContext()) +//{ +// //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } ); +// context.SaveChanges(); - } - else - { - Console.WriteLine("Not Found"); - } +// ChampionEntity champ = context.Find("Akali"); - //Test BDD Skills - ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" }; +// if( champ != null) +// { +// Console +// .WriteLine(champ.ToString()); - //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }; - SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate }; - SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive }; +// } +// else +// { +// Console.WriteLine("Not Found"); +// } - champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }); - champSkill.AddSkill(s2); - champSkill.AddSkill(s3); +// //Test BDD Skills +// ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" }; - context.Add(champSkill); +// //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }; +// SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate }; +// SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive }; - context.SaveChanges(); +// champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }); +// champSkill.AddSkill(s2); +// champSkill.AddSkill(s3); +// context.Add(champSkill); - //OneToMany - Console.WriteLine("Champions : "); - foreach (var champi in context.Champions.Include(a => a.skins)) - { - Console.WriteLine($"\t{champi.Name} : {champi.Bio}"); - foreach (var s in champi.skins) - { - Console.WriteLine($"\t\t{s.Name}"); - } - } +// context.SaveChanges(); - Console.WriteLine(); - Console.WriteLine("Skin :"); - foreach (var s in context.Skins) - { - Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})"); - } +// //OneToMany +// Console.WriteLine("Champions : "); +// foreach (var champi in context.Champions.Include(a => a.skins)) +// { +// Console.WriteLine($"\t{champi.Name} : {champi.Bio}"); +// foreach (var s in champi.skins) +// { +// Console.WriteLine($"\t\t{s.Name}"); +// } +// } +// Console.WriteLine(); - Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n"); +// Console.WriteLine("Skin :"); +// foreach (var s in context.Skins) +// { +// Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})"); +// } - ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"}; - SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel}, - new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel }, - new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel }, - new SkinEntity { Name = "Time's Lie", Champion = captainMarvel }, - new SkinEntity { Name = "Lush Life", Champion = captainMarvel }, - new SkinEntity { Name = "Day Waves", Champion = captainMarvel } - }; - foreach (var s in skins) - { - captainMarvel.skins.Add(s); - } - context.Add(captainMarvel); - context.SaveChanges(); +// Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n"); +// ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"}; +// SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel}, +// new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel }, +// new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel }, +// new SkinEntity { Name = "Time's Lie", Champion = captainMarvel }, +// new SkinEntity { Name = "Lush Life", Champion = captainMarvel }, +// new SkinEntity { Name = "Day Waves", Champion = captainMarvel } +// }; +// foreach (var s in skins) +// { +// captainMarvel.skins.Add(s); +// } -} +// context.Add(captainMarvel); +// context.SaveChanges(); + + +//} -- 2.36.3