diff --git a/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs b/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs index d7f3cd0..3a5665b 100644 --- a/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs +++ b/EntityFramework_LoL/Sources/Entities/ChampionDbContext.cs @@ -1,9 +1,13 @@ using Microsoft.EntityFrameworkCore; +using Shared; +using System.Security.Claims; +using System.Xml.Linq; namespace Entities { public class ChampionDbContext : DbContext { + public DbSet skins { get; set; } public DbSet champions { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { @@ -13,17 +17,39 @@ namespace Entities protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasData(new List() { - new ChampionEntity + new() { Name = "Dave", Bio = "Le meilleur Jazzman de France", + Class = ChampionClass.Fighter }, - new ChampionEntity + new() { - Name = "Armure", + Name = "Armure", Bio = "Solide", + Class = ChampionClass.Tank } }); + + + modelBuilder.Entity().HasData(new List() { + new SkinEntity + { + Name = "Dave de glace", + Description = "Enneigé", + Icon = "aaa", + ChampionForeignKey = "Dave", + Price=7.99F + }, + new SkinEntity + { + Name = "Armure Fullspeed", + Description = "Deja vu", + Icon = "aaa", + ChampionForeignKey = "Armure", + Price=9.99F + }, + }); } } } diff --git a/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs b/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs index 27499d9..8ed2a5c 100644 --- a/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs +++ b/EntityFramework_LoL/Sources/Entities/ChampionEntity.cs @@ -1,15 +1,18 @@ -using System.ComponentModel.DataAnnotations; +using Shared; +using System.ComponentModel.DataAnnotations; namespace Entities { public class ChampionEntity { [Key] [MaxLength(256)] - public string? Name { get; set; } + public string Name { get; set; } [Required] [MaxLength(500)] public string Bio { get; set; } public string? Icon { get; set; } + [Required] + public ChampionClass Class { get; set;} } } diff --git a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal index c1c99f1..c9dd033 100644 Binary files a/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal and b/EntityFramework_LoL/Sources/Entities/Entities.Champions.db-wal differ diff --git a/EntityFramework_LoL/Sources/Entities/Entities.csproj b/EntityFramework_LoL/Sources/Entities/Entities.csproj index 3707fee..ef6f098 100644 --- a/EntityFramework_LoL/Sources/Entities/Entities.csproj +++ b/EntityFramework_LoL/Sources/Entities/Entities.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs deleted file mode 100644 index b71d075..0000000 --- a/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.Designer.cs +++ /dev/null @@ -1,55 +0,0 @@ -// -using Entities; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Entities.Migrations -{ - [DbContext(typeof(ChampionDbContext))] - [Migration("20230204100209_myFirstMigration")] - partial class myFirstMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("Entities.ChampionEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Icon") - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("champions"); - - b.HasData( - new - { - Name = "Dave", - Bio = "Le meilleur Jazzman de France" - }, - new - { - Name = "Armure", - Bio = "Solide" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs deleted file mode 100644 index 30af7dd..0000000 --- a/EntityFramework_LoL/Sources/Entities/Migrations/20230204100209_myFirstMigration.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace Entities.Migrations -{ - /// - public partial class myFirstMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "champions", - columns: table => new - { - Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), - Bio = table.Column(type: "TEXT", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_champions", x => x.Name); - }); - - migrationBuilder.InsertData( - table: "champions", - columns: new[] { "Name", "Bio", "Icon" }, - values: new object[,] - { - { "Armure", "Solide", null }, - { "Dave", "Le meilleur Jazzman de France", null } - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "champions"); - } - } -} diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230204105739_myFirstMigration.Designer.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230204105739_myFirstMigration.Designer.cs new file mode 100644 index 0000000..78252d6 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230204105739_myFirstMigration.Designer.cs @@ -0,0 +1,118 @@ +// +using Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Entities.Migrations +{ + [DbContext(typeof(ChampionDbContext))] + [Migration("20230204105739_myFirstMigration")] + partial class myFirstMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("Entities.ChampionEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("champions"); + + b.HasData( + new + { + Name = "Dave", + Bio = "Le meilleur Jazzman de France", + Class = 2 + }, + new + { + Name = "Armure", + Bio = "Solide", + Class = 6 + }); + }); + + modelBuilder.Entity("Entities.SkinEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("skins"); + + b.HasData( + new + { + Name = "Dave de glace", + ChampionForeignKey = "Dave", + Description = "Enneigé", + Icon = "aaa", + Price = 7.99f + }, + new + { + Name = "Armure Fullspeed", + ChampionForeignKey = "Armure", + Description = "Deja vu", + Icon = "aaa", + Price = 9.99f + }); + }); + + modelBuilder.Entity("Entities.SkinEntity", b => + { + b.HasOne("Entities.ChampionEntity", "Champion") + .WithMany() + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/20230204105739_myFirstMigration.cs b/EntityFramework_LoL/Sources/Entities/Migrations/20230204105739_myFirstMigration.cs new file mode 100644 index 0000000..a628a29 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/Migrations/20230204105739_myFirstMigration.cs @@ -0,0 +1,84 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace Entities.Migrations +{ + /// + public partial class myFirstMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "champions", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Bio = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: true), + Class = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_champions", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "skins", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false), + ChampionForeignKey = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_skins", x => x.Name); + table.ForeignKey( + name: "FK_skins_champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, + principalTable: "champions", + principalColumn: "Name", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "champions", + columns: new[] { "Name", "Bio", "Class", "Icon" }, + values: new object[,] + { + { "Armure", "Solide", 6, null }, + { "Dave", "Le meilleur Jazzman de France", 2, null } + }); + + migrationBuilder.InsertData( + table: "skins", + columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "Price" }, + values: new object[,] + { + { "Armure Fullspeed", "Armure", "Deja vu", "aaa", 9.99f }, + { "Dave de glace", "Dave", "Enneigé", "aaa", 7.99f } + }); + + migrationBuilder.CreateIndex( + name: "IX_skins_ChampionForeignKey", + table: "skins", + column: "ChampionForeignKey"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "skins"); + + migrationBuilder.DropTable( + name: "champions"); + } + } +} diff --git a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs b/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs index 3595433..f17b1cf 100644 --- a/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs +++ b/EntityFramework_LoL/Sources/Entities/Migrations/ChampionDbContextModelSnapshot.cs @@ -27,6 +27,9 @@ namespace Entities.Migrations .HasMaxLength(500) .HasColumnType("TEXT"); + b.Property("Class") + .HasColumnType("INTEGER"); + b.Property("Icon") .HasColumnType("TEXT"); @@ -38,14 +41,74 @@ namespace Entities.Migrations new { Name = "Dave", - Bio = "Le meilleur Jazzman de France" + Bio = "Le meilleur Jazzman de France", + Class = 2 }, new { Name = "Armure", - Bio = "Solide" + Bio = "Solide", + Class = 6 }); }); + + modelBuilder.Entity("Entities.SkinEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionForeignKey"); + + b.ToTable("skins"); + + b.HasData( + new + { + Name = "Dave de glace", + ChampionForeignKey = "Dave", + Description = "Enneigé", + Icon = "aaa", + Price = 7.99f + }, + new + { + Name = "Armure Fullspeed", + ChampionForeignKey = "Armure", + Description = "Deja vu", + Icon = "aaa", + Price = 9.99f + }); + }); + + modelBuilder.Entity("Entities.SkinEntity", b => + { + b.HasOne("Entities.ChampionEntity", "Champion") + .WithMany() + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + }); #pragma warning restore 612, 618 } } diff --git a/EntityFramework_LoL/Sources/Entities/Program.cs b/EntityFramework_LoL/Sources/Entities/Program.cs index 2acf068..6e4348a 100644 --- a/EntityFramework_LoL/Sources/Entities/Program.cs +++ b/EntityFramework_LoL/Sources/Entities/Program.cs @@ -1,14 +1,16 @@ using Entities; +using Shared; -ChampionEntity dave = new() +ChampionEntity imri = new() { Name = "Imri Cartel", Bio = "Fou Furieux", + Class = ChampionClass.Assassin }; using (var context = new ChampionDbContext()) { // Crée des nounours et les insère dans la base Console.WriteLine("Creates and inserts new Champion"); - context.Add(dave); + context.Add(imri); context.SaveChanges(); } diff --git a/EntityFramework_LoL/Sources/Entities/SkinEntity.cs b/EntityFramework_LoL/Sources/Entities/SkinEntity.cs new file mode 100644 index 0000000..0baace0 --- /dev/null +++ b/EntityFramework_LoL/Sources/Entities/SkinEntity.cs @@ -0,0 +1,32 @@ +using Shared; +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 Entities +{ + public class SkinEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + [Required] + [MaxLength(500)] + public string Description { get; set; } + [Required] + public string Icon { get; set; } + [Required] + public float Price { get; set; } + + [Required] + public string ChampionForeignKey { get; set; } + + [ForeignKey("ChampionForeignKey")] + public ChampionEntity Champion { get; set; } + + } +} diff --git a/EntityFramework_LoL/Sources/Model/Champion.cs b/EntityFramework_LoL/Sources/Model/Champion.cs index fd4a5ca..9b7e96d 100644 --- a/EntityFramework_LoL/Sources/Model/Champion.cs +++ b/EntityFramework_LoL/Sources/Model/Champion.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using Shared; +using System.Collections.Immutable; using System.Collections.ObjectModel; using System.Numerics; using System.Text; diff --git a/EntityFramework_LoL/Sources/Model/Model.csproj b/EntityFramework_LoL/Sources/Model/Model.csproj index 89f6363..53e6be4 100644 --- a/EntityFramework_LoL/Sources/Model/Model.csproj +++ b/EntityFramework_LoL/Sources/Model/Model.csproj @@ -9,9 +9,6 @@ - - - diff --git a/EntityFramework_LoL/Sources/Model/Rune.cs b/EntityFramework_LoL/Sources/Model/Rune.cs index 7b5047b..368582a 100644 --- a/EntityFramework_LoL/Sources/Model/Rune.cs +++ b/EntityFramework_LoL/Sources/Model/Rune.cs @@ -1,4 +1,4 @@ -using System; +using Shared; namespace Model { diff --git a/EntityFramework_LoL/Sources/Model/RunePage.cs b/EntityFramework_LoL/Sources/Model/RunePage.cs index cf56628..0dbb7ab 100644 --- a/EntityFramework_LoL/Sources/Model/RunePage.cs +++ b/EntityFramework_LoL/Sources/Model/RunePage.cs @@ -1,4 +1,4 @@ -using System; +using Shared; using System.Collections.ObjectModel; namespace Model diff --git a/EntityFramework_LoL/Sources/Model/Skill.cs b/EntityFramework_LoL/Sources/Model/Skill.cs index 0679ea6..16f947e 100644 --- a/EntityFramework_LoL/Sources/Model/Skill.cs +++ b/EntityFramework_LoL/Sources/Model/Skill.cs @@ -1,4 +1,4 @@ -using System; +using Shared; namespace Model { diff --git a/EntityFramework_LoL/Sources/Model/enums/ChampionClass.cs b/EntityFramework_LoL/Sources/Shared/enums/ChampionClass.cs similarity index 77% rename from EntityFramework_LoL/Sources/Model/enums/ChampionClass.cs rename to EntityFramework_LoL/Sources/Shared/enums/ChampionClass.cs index d169512..701b297 100644 --- a/EntityFramework_LoL/Sources/Model/enums/ChampionClass.cs +++ b/EntityFramework_LoL/Sources/Shared/enums/ChampionClass.cs @@ -1,5 +1,4 @@ -using System; -namespace Model +namespace Shared { public enum ChampionClass { diff --git a/EntityFramework_LoL/Sources/Model/enums/RuneFamily.cs b/EntityFramework_LoL/Sources/Shared/enums/RuneFamily.cs similarity index 68% rename from EntityFramework_LoL/Sources/Model/enums/RuneFamily.cs rename to EntityFramework_LoL/Sources/Shared/enums/RuneFamily.cs index 07a232c..b025487 100644 --- a/EntityFramework_LoL/Sources/Model/enums/RuneFamily.cs +++ b/EntityFramework_LoL/Sources/Shared/enums/RuneFamily.cs @@ -1,5 +1,4 @@ -using System; -namespace Model +namespace Shared { public enum RuneFamily { diff --git a/EntityFramework_LoL/Sources/Model/RunePage.Category.cs b/EntityFramework_LoL/Sources/Shared/enums/RunePage.Category.cs similarity index 60% rename from EntityFramework_LoL/Sources/Model/RunePage.Category.cs rename to EntityFramework_LoL/Sources/Shared/enums/RunePage.Category.cs index 1047c0e..2ee019d 100644 --- a/EntityFramework_LoL/Sources/Model/RunePage.Category.cs +++ b/EntityFramework_LoL/Sources/Shared/enums/RunePage.Category.cs @@ -1,8 +1,5 @@ -using System; -namespace Model +namespace Shared { - public partial class RunePage - { public enum Category { Major, @@ -12,6 +9,5 @@ namespace Model OtherMinor1, OtherMinor2 } - } } diff --git a/EntityFramework_LoL/Sources/Model/enums/SkillType.cs b/EntityFramework_LoL/Sources/Shared/enums/SkillType.cs similarity index 69% rename from EntityFramework_LoL/Sources/Model/enums/SkillType.cs rename to EntityFramework_LoL/Sources/Shared/enums/SkillType.cs index d7fc8da..3e48028 100644 --- a/EntityFramework_LoL/Sources/Model/enums/SkillType.cs +++ b/EntityFramework_LoL/Sources/Shared/enums/SkillType.cs @@ -1,5 +1,4 @@ -using System; -namespace Model +namespace Shared { public enum SkillType { diff --git a/EntityFramework_LoL/Sources/StubLib/StubData.Champions.cs b/EntityFramework_LoL/Sources/StubLib/StubData.Champions.cs index ad19275..8ed1220 100644 --- a/EntityFramework_LoL/Sources/StubLib/StubData.Champions.cs +++ b/EntityFramework_LoL/Sources/StubLib/StubData.Champions.cs @@ -1,5 +1,6 @@ using System; using Model; +using Shared; namespace StubLib { diff --git a/EntityFramework_LoL/Sources/StubLib/StubData.Runes.cs b/EntityFramework_LoL/Sources/StubLib/StubData.Runes.cs index f0e8802..32fce54 100644 --- a/EntityFramework_LoL/Sources/StubLib/StubData.Runes.cs +++ b/EntityFramework_LoL/Sources/StubLib/StubData.Runes.cs @@ -1,5 +1,6 @@ using System; using Model; +using Shared; namespace StubLib { diff --git a/EntityFramework_LoL/Sources/Tests/ConsoleTests/Program.cs b/EntityFramework_LoL/Sources/Tests/ConsoleTests/Program.cs index 93e266f..d642ce2 100644 --- a/EntityFramework_LoL/Sources/Tests/ConsoleTests/Program.cs +++ b/EntityFramework_LoL/Sources/Tests/ConsoleTests/Program.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using Microsoft.Extensions.DependencyInjection; using Model; +using Shared; using StubLib; using static System.Console;