diff --git a/Sources/API_LoL/Program.cs b/Sources/API_LoL/Program.cs index 7c535a4..f1b44d0 100644 --- a/Sources/API_LoL/Program.cs +++ b/Sources/API_LoL/Program.cs @@ -13,7 +13,7 @@ var builder = WebApplication.CreateBuilder(args); ///NOT WORKING WHEN CHANGING VERSIONS : /// voir sur https://blog.christian-schou.dk/how-to-use-api-versioning-in-net-core-web-api/ rubrique "Configure SwaggerOptions" -/// (mais requiere l'injection de dépendance). +/// (mais requiere l'injection de d�pendance). /// Sinon, code plus simple disponible par le prof @@ -39,6 +39,11 @@ builder.Services.AddControllers(); +//builder.Services.AddScoped(); + + +builder.Services.AddHttpClient(); + //builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs index 456b9ce..c090b08 100644 --- a/Sources/EntityFramework/ChampionEntity.cs +++ b/Sources/EntityFramework/ChampionEntity.cs @@ -42,6 +42,9 @@ namespace EntityFramework //public LargeImageEntity? Image { get; set; } ====> voir pour faire "plus propre" => créé une table pour l'entity Largeimage public string? Image { get; set; } + // Pour le many to many Champion *<---->* RunePage + public ICollection RunePageEntities{ get; set; } + /// diff --git a/Sources/EntityFramework/EnumCategory.cs b/Sources/EntityFramework/EnumCategory.cs new file mode 100644 index 0000000..8276ed2 --- /dev/null +++ b/Sources/EntityFramework/EnumCategory.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + public enum EnumCategory + { + Major, + Minor1, + Minor2, + Minor3, + OtherMinor1, + OtherMinor2 + } +} diff --git a/Sources/EntityFramework/EnumRuneFamily.cs b/Sources/EntityFramework/EnumRuneFamily.cs new file mode 100644 index 0000000..cbeacc0 --- /dev/null +++ b/Sources/EntityFramework/EnumRuneFamily.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + public enum EnumRuneFamily + { + Unknown, + Precision, + Domination + } +} diff --git a/Sources/EntityFramework/LoLDbContext.cs b/Sources/EntityFramework/LoLDbContext.cs index 003ff03..042b646 100644 --- a/Sources/EntityFramework/LoLDbContext.cs +++ b/Sources/EntityFramework/LoLDbContext.cs @@ -16,6 +16,10 @@ namespace EntityFramework public DbSet Image { get; set; } + public DbSet Rune { get; set; } + + public DbSet RunePage { get; set; } + public LoLDbContext() { } @@ -39,7 +43,7 @@ namespace EntityFramework //modelBuilder.Entity().Property(entity => entity.Id) // .ValueGeneratedOnAdd(); - + modelBuilder.Entity().Property(entity => entity.Name) .IsRequired() .HasMaxLength(50); @@ -71,6 +75,26 @@ namespace EntityFramework .WithMany(champion => champion.skins) .HasForeignKey("ChampionEntityForeignKey"); + + + + + // Many to Many ChampionEntity - RunePageEntity + modelBuilder.Entity().HasKey(entity => entity.Name); + modelBuilder.Entity().HasKey(entity => entity.Name); + modelBuilder.Entity().ToTable("RunePage"); + + + // Use the shadow property as a foreign key + modelBuilder.Entity() + .HasMany(r => r.Champion) + .WithMany(c => c.RunePageEntities); + //.HasForeignKey("AlbumForeignKey"); + + modelBuilder.Entity() + .HasMany(c => c.RunePageEntities) + .WithMany(r => r.Champion); + //.HasForeignKey("AlbumForeignKey"); } } } diff --git a/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs b/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs deleted file mode 100644 index 2a90b9d..0000000 --- a/Sources/EntityFramework/Migrations/20230319224555_myMig.Designer.cs +++ /dev/null @@ -1,175 +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("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 deleted file mode 100644 index 0e61c80..0000000 --- a/Sources/EntityFramework/Migrations/20230319224555_myMig.cs +++ /dev/null @@ -1,122 +0,0 @@ -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 deleted file mode 100644 index e00a86a..0000000 --- a/Sources/EntityFramework/Migrations/LoLDBContextWithStubModelSnapshot.cs +++ /dev/null @@ -1,172 +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.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/Program.cs b/Sources/EntityFramework/Program.cs index 8c67f3f..56915f8 100644 --- a/Sources/EntityFramework/Program.cs +++ b/Sources/EntityFramework/Program.cs @@ -3,6 +3,40 @@ using EntityFramework; using EntityFramework.Manager; using Microsoft.EntityFrameworkCore; using Model; +using System.Buffers.Text; + +using ( var context = new LoLDbContext()) +{ + //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } ); + context.SaveChanges(); + + ChampionEntity champ = context.Find("Akali"); + + if( champ != null) + { + Console + .WriteLine(champ.ToString()); + + } + else + { + Console.WriteLine("Not Found"); + } + + //Test BDD Skills + ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" }; + + //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown }; + SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type= EntityFramework.SkillType.Ultimate }; + SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = EntityFramework.SkillType.Passive }; + + champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = EntityFramework.SkillType.Unknown }); + champSkill.AddSkill(s2); + champSkill.AddSkill(s3); + + context.Add(champSkill); + + context.SaveChanges(); IDataManager dataManager = new EFDataManager(); IChampionsManager championsManager = dataManager.ChampionsMgr; @@ -64,6 +98,18 @@ Console.WriteLine(champions.First().Name); // } + var r1 = new RuneEntity { Name = "Rune1", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }; + var r2 = new RuneEntity { Name = "Rune2", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }; + var corichard = new ChampionEntity { Name = "Corichard", Bio = "biobio", Icon = "Icon.png" }; + var pintrand = new ChampionEntity { Name = "Pintrand", Bio = "biobio", Icon = "Icon.png" }; + var rp1 = new RunePageEntity { Name = "RP1", Rune = new RuneEntity { Name = "aa", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }, Champion = new List { corichard } }; + var rp2 = new RunePageEntity { Name = "RP2", Rune = new RuneEntity{ Name = "aaa", Description = "aaa", Family = EnumRuneFamily.Domination, Image = new LargeImage("base") }, Champion = new List { pintrand } }; + + context.Rune.AddRange(new[] { r1, r2 }); + context.Champions.AddRange(new[] { corichard, pintrand }); + context.RunePage.AddRange(new[] { rp1, rp2 }); + 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"}; diff --git a/Sources/EntityFramework/RuneEntity.cs b/Sources/EntityFramework/RuneEntity.cs new file mode 100644 index 0000000..c9de7da --- /dev/null +++ b/Sources/EntityFramework/RuneEntity.cs @@ -0,0 +1,24 @@ +using Model; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EntityFramework +{ + //[Table("Rune")] + public class RuneEntity + { + [Key] + public string Name; + + public string Description; + + public EnumRuneFamily Family; + + public LargeImage Image; + } +} diff --git a/Sources/EntityFramework/RunePageEntity.cs b/Sources/EntityFramework/RunePageEntity.cs new file mode 100644 index 0000000..842806b --- /dev/null +++ b/Sources/EntityFramework/RunePageEntity.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Model.RunePage; + +namespace EntityFramework +{ + public class RunePageEntity + { + [Key] + public string Name { get; set; } + + public RuneEntity? Rune { get; set; } + + //? voir si cela pause probleme + public Dictionary Dico = new Dictionary(); + + // Pour le many to many Champion *<---->* RunePage + public ICollection Champion{ get; set; } + + + + public void CheckRunes(EnumCategory newRuneCategory){} + public void CheckFamilies(EnumCategory cat1, EnumCategory cat2){} + public void UpdateMajorFamily(EnumCategory minor, bool expectedValue){} + } +} diff --git a/Sources/EntityFramework/StubbedContext.cs b/Sources/EntityFramework/StubbedContext.cs index 833f0c7..3731035 100644 --- a/Sources/EntityFramework/StubbedContext.cs +++ b/Sources/EntityFramework/StubbedContext.cs @@ -18,8 +18,11 @@ namespace EntityFramework { 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" }; + ChampionEntity pintrand = new ChampionEntity { Name = "Pintrand", Bio = "mimimimimim", Icon = "/small.png" }; + + RuneEntity r1 = new RuneEntity { Name = "FirstRune", Description = "desc", Family = EnumRuneFamily.Domination }; + RuneEntity r2 = new RuneEntity { Name = "SecondRune", Description = "desc", Family = EnumRuneFamily.Unknown }; //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" } }; @@ -27,17 +30,21 @@ namespace EntityFramework 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 } - ); + 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 } + ); + + modelBuilder.Entity().HasData(new { Name = "RP1", Rune = r1, Champion = corichard}, + new { Name = "RP2", Rune = r2, Champion = pintrand} + ); } } diff --git a/Sources/EntityFramework/champion.db b/Sources/EntityFramework/champion.db deleted file mode 100644 index d6b07a7..0000000 Binary files a/Sources/EntityFramework/champion.db and /dev/null differ diff --git a/Sources/HttpClient/HttpClient.csproj b/Sources/HttpClient/HttpClient.csproj new file mode 100644 index 0000000..9e4e01f --- /dev/null +++ b/Sources/HttpClient/HttpClient.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Sources/HttpClient/HttpClientManager.Champion.cs b/Sources/HttpClient/HttpClientManager.Champion.cs new file mode 100644 index 0000000..9ffc79b --- /dev/null +++ b/Sources/HttpClient/HttpClientManager.Champion.cs @@ -0,0 +1,128 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Json; +using System.Reflection; +using System.Reflection.Metadata; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace HttpClient +{ + public partial class HttpClientManager + { + public class ChampionManager : IChampionsManager + { + + + private readonly HttpClientManager parent; + + private System.Net.Http.HttpClient httpc; + + public string BaseAddress; + + + public ChampionManager(HttpClientManager parent, System.Net.Http.HttpClient httpc) { + + this.httpc = httpc; + this.parent = parent; + } + + public async Task AddItem(Champion? item) //return le champion ajouté, null sinon ? + { + if(item==null) throw new ArgumentNullException("item is null"); + var response = await httpc.PostAsJsonAsync("/Champion?Name = " + item.Name, item); + + return response.IsSuccessStatusCode ? item : null; + } + + public async Task DeleteItem(Champion? item) + { + HttpResponseMessage response = await httpc.DeleteAsync("/Champion?Name=" + item.Name); + return response.IsSuccessStatusCode; + } + + public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) + { + return httpc.GetFromJsonAsync>("/Champion?index="+index+"&size="+count); + } + + + + + + public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) + { + throw new NotImplementedException(); + } + + public Task> GetItemsByClass(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) + { + return httpc.GetFromJsonAsync>("/Champion?name="+substring+"&index=" + index + "&size=" + count); + } + + 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(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/HttpClient/HttpClientManager.cs b/Sources/HttpClient/HttpClientManager.cs new file mode 100644 index 0000000..49ddb70 --- /dev/null +++ b/Sources/HttpClient/HttpClientManager.cs @@ -0,0 +1,29 @@ +using Model; + +namespace HttpClient +{ + public partial class HttpClientManager : IDataManager + { + + + public System.Net.Http.HttpClient httpC { get; set; } = new System.Net.Http.HttpClient(); + + public string BaseAddress; + + + public HttpClientManager() { + ChampionsMgr = new ChampionManager(this, httpC); + httpC.BaseAddress = new Uri("https://localhost:7144/api/"); + + } + + public ISkinsManager SkinsMgr => throw new NotImplementedException(); + + public IRunesManager RunesMgr => throw new NotImplementedException(); + + public IRunePagesManager RunePagesMgr => throw new NotImplementedException(); + + public IChampionsManager ChampionsMgr { get; set; } + + } +} diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index a5d27bb..007e972 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api_UT", "Api_UT\Api_UT.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EF_UT", "EF_UT\EF_UT.csproj", "{74F469C3-A94A-4507-9DC7-7DBADCD18173}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClient", "HttpClient\HttpClient.csproj", "{DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -64,6 +66,10 @@ Global {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Debug|Any CPU.Build.0 = Debug|Any CPU {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.ActiveCfg = Release|Any CPU {74F469C3-A94A-4507-9DC7-7DBADCD18173}.Release|Any CPU.Build.0 = Release|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE2E40D5-1B4D-491C-B7E7-4E91B32DB93F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE