diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..dd32bbc --- /dev/null +++ b/.drone.yml @@ -0,0 +1,66 @@ +kind: pipeline +type: docker +name: default + +trigger: + event: + - push + +steps: + - name: build + image: mcr.microsoft.com/dotnet/sdk:6.0 + volumes: + - name: docs + path: /docs + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet build LeagueOfLegends.sln -c Release --no-restore + - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + + - name: tests + image: mcr.microsoft.com/dotnet/sdk:6.0 + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet test LeagueOfLegends.sln --no-restore + depends_on: [build] + + - name: code-analysis + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 + commands: + - cd Sources/ + - dotnet restore LeagueOfLegends.sln + - dotnet sonarscanner begin /k:TEST /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + - dotnet build LeagueOfLegends.sln -c Release --no-restore + - dotnet test LeagueOfLegends.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + secrets: [ SECRET_SONAR_LOGIN ] + settings: + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + sonar_host: https://codefirst.iut.uca.fr/sonar/ + # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} + sonar_token: + from_secret: SECRET_SONAR_LOGIN + depends_on: [tests] + + - name: generate-and-deploy-docs + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer + failure: ignore + volumes: + - name: docs + path: /docs + commands: + #- cd Documentation/doxygen + #- doxygen Doxyfile + - /entrypoint.sh + when: + branch: + - master + depends_on: [ build ] + +volumes: +- name: docs + temp: {} diff --git a/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs b/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs deleted file mode 100644 index f7d3a11..0000000 --- a/Sources/EntityFrameworkLOL/DBContexts/ChampionContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -using EntityFrameworkLOL.Entities; -using Microsoft.EntityFrameworkCore; - -namespace EntityFrameworkLOL.DBContexts -{ - class ChampionContext : DbContext - { - public DbSet Champion { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlite($"Data Source=DBLOL.db"); - } -} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs b/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs deleted file mode 100644 index daa69f9..0000000 --- a/Sources/EntityFrameworkLOL/DBContexts/RuneContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -using EntityFrameworkLOL.Entities; -using Microsoft.EntityFrameworkCore; - -namespace EntityFrameworkLOL.DBContexts -{ - class RuneContext : DbContext - { - public DbSet Rune { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlite($"Data Source=DBLOL.db"); - } -} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs index 8c31903..dba6295 100644 --- a/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs +++ b/Sources/EntityFrameworkLOL/DBContexts/SQLiteContext.cs @@ -5,11 +5,25 @@ namespace EntityFrameworkLOL.DBContexts { class SQLiteContext : DbContext { - /*public DbSet Champion { get; set; } - public DbSet Skin { get; set; }*/ + public DbSet Category { get; set; } + public DbSet RuneFamily { get; set; } + public DbSet Image { get; set; } + public DbSet SkillType { get; set; } + //public DbSet Skill { get; set; } + public DbSet Skin { get; set; } public DbSet Rune { get; set; } + public DbSet ChampionClass { get; set; } + public DbSet RunePage { get; set; } + public DbSet Champion { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite($"Data Source=DBLOL.db"); + + public SQLiteContext() + { } + + public SQLiteContext(DbContextOptions options) + : base(options) + { } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs b/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs deleted file mode 100644 index 5628c53..0000000 --- a/Sources/EntityFrameworkLOL/DBContexts/SkinContext.cs +++ /dev/null @@ -1,13 +0,0 @@ -using EntityFrameworkLOL.Entities; -using Microsoft.EntityFrameworkCore; - -namespace EntityFrameworkLOL.DBContexts -{ - class SkinContext : DbContext - { - public DbSet Skin { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder options) - => options.UseSqlite($"Data Source=DBLOL.db"); - } -} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/DBLOL.db b/Sources/EntityFrameworkLOL/DBLOL.db index e1ce9c7..b647dff 100644 Binary files a/Sources/EntityFrameworkLOL/DBLOL.db and b/Sources/EntityFrameworkLOL/DBLOL.db differ diff --git a/Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs b/Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs new file mode 100644 index 0000000..caa6ded --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/CategoryEntity.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using System.Xml.Linq; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; +using Model; +using static System.Net.Mime.MediaTypeNames; +using System.Reflection.PortableExecutable; +using System.Security.Claims; + +namespace EntityFrameworkLOL.Entities +{ + class CategoryEntity + { + [Key] + [ForeignKey("RunePageEntity")] + public RunePage.Category Category { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/ChamionClassEntity.cs b/Sources/EntityFrameworkLOL/Entities/ChamionClassEntity.cs new file mode 100644 index 0000000..8a75e0d --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/ChamionClassEntity.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using Model; +using System.ComponentModel.DataAnnotations.Schema; + +namespace EntityFrameworkLOL.Entities +{ + class ChampionClassEntity + { + [Key] + [ForeignKey("ChampionEntity")] + public int Id { get; set; } + + public ChampionClass Class { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs index fcc602e..bfd6593 100644 --- a/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/ChampionEntity.cs @@ -6,6 +6,12 @@ using System.Collections.Generic; using System.Text; using System.ComponentModel.DataAnnotations; using System.Xml.Linq; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; +using Model; +using static System.Net.Mime.MediaTypeNames; +using System.Reflection.PortableExecutable; +using System.Security.Claims; namespace EntityFrameworkLOL.Entities { @@ -17,5 +23,15 @@ namespace EntityFrameworkLOL.Entities public string Bio { get; set; } public string Icon { get; set; } + + [NotMapped] + public Dictionary Characteristics { get; set; } + // Switch Dictionary to List puis faudra juste mapper la liste en dico + + public ChampionClassEntity Class { get; set; } + + public ImageEntity Image { get; set; } + + //public ICollection Skills { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs b/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs new file mode 100644 index 0000000..07a6d91 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/ImageEntity.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using System.Xml.Linq; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; +using Model; +using static System.Net.Mime.MediaTypeNames; +using System.Reflection.PortableExecutable; +using System.Security.Claims; + +namespace EntityFrameworkLOL.Entities +{ + class ImageEntity + { + [Key] + [ForeignKey("ChampionEntity")] + public string Base64 { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs index 7ceb423..f313cdf 100644 --- a/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/RuneEntity.cs @@ -14,5 +14,9 @@ namespace EntityFrameworkLOL.Entities public string Name { get; set; } public string Description { get; set; } + + public ImageEntity Image { get; set; } + + public RuneFamilyEntity Family { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs b/Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs new file mode 100644 index 0000000..c7369ad --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/RuneFamilyEntity.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using Model; +using System.ComponentModel.DataAnnotations.Schema; + +namespace EntityFrameworkLOL.Entities +{ + class RuneFamilyEntity + { + [Key] + [ForeignKey("RuneEntity")] + public int Id { get; set; } + + public RuneFamily Family { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs new file mode 100644 index 0000000..e99dd61 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/RunePageEntity.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using System.Xml.Linq; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations.Schema; +using Model; +using static System.Net.Mime.MediaTypeNames; +using System.Reflection.PortableExecutable; +using System.Security.Claims; + +namespace EntityFrameworkLOL.Entities +{ + class RunePageEntity + { + [Key] + public string Name { get; set; } + + [NotMapped] + public Dictionary Dictionary { get; set; } + // Switch Dictionary to List puis faudra juste mapper la liste en dico + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs new file mode 100644 index 0000000..dbefb19 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/SkillEntity.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace EntityFrameworkLOL.Entities +{ + class SkillEntity + { + [Key] + public string Name { get; set; } + + public string Description { get; set; } + + public SkillTypeEntity Type { get; set; } + + [NotMapped] + public ICollection Champions { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs new file mode 100644 index 0000000..b17df20 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Entities/SkillTypeEntity.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using System.ComponentModel.DataAnnotations; +using Model; +using System.ComponentModel.DataAnnotations.Schema; + +namespace EntityFrameworkLOL.Entities +{ + class SkillTypeEntity + { + [Key] + [ForeignKey("SkillEntity")] + public SkillType Type { get; set; } + } +} \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs index 9412f33..d14983b 100644 --- a/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs +++ b/Sources/EntityFrameworkLOL/Entities/SkinEntity.cs @@ -15,8 +15,12 @@ namespace EntityFrameworkLOL.Entities public string Description { get; set; } - /*public string Icon { get; set; } + public string Icon { get; set; } - public float Price { get; set; }*/ + public float Price { get; set; } + + public ImageEntity Image { get; set; } + + public ChampionEntity ChampionSkin { get; set; } } } \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj index 40baca6..9c01959 100644 --- a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj +++ b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj @@ -1,10 +1,11 @@ - + Exe net6.0 enable enable + $(MSBuildProjectDirectory) @@ -24,4 +25,8 @@ + + + + \ No newline at end of file diff --git a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs deleted file mode 100644 index da7a0e3..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.Designer.cs +++ /dev/null @@ -1,38 +0,0 @@ -// -using EntityFrameworkLOL.DBContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - [DbContext(typeof(SQLiteContext))] - [Migration("20230202105714_MigrationWallah2")] - partial class MigrationWallah2 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => - { - b.Property("Name") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Name"); - - b.ToTable("Rune"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs b/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs deleted file mode 100644 index 0150ec7..0000000 --- a/Sources/EntityFrameworkLOL/Migrations/20230202105714_MigrationWallah2.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EntityFrameworkLOL.Migrations -{ - /// - public partial class MigrationWallah2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Rune", - columns: table => new - { - Name = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Rune", x => x.Name); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Rune"); - } - } -} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230208161248_MigrationWallah4.Designer.cs b/Sources/EntityFrameworkLOL/Migrations/20230208161248_MigrationWallah4.Designer.cs new file mode 100644 index 0000000..e79b656 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/20230208161248_MigrationWallah4.Designer.cs @@ -0,0 +1,227 @@ +// +using EntityFrameworkLOL.DBContexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EntityFrameworkLOL.Migrations +{ + [DbContext(typeof(SQLiteContext))] + [Migration("20230208161248_MigrationWallah4")] + partial class MigrationWallah4 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.CategoryEntity", b => + { + b.Property("Category") + .HasColumnType("INTEGER"); + + b.HasKey("Category"); + + b.ToTable("Category"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionClassEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("ChampionClass"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ClassId") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("ClassId"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ImageEntity", b => + { + b.Property("Base64") + .HasColumnType("TEXT"); + + b.HasKey("Base64"); + + b.ToTable("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("FamilyId") + .HasColumnType("INTEGER"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("FamilyId"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Rune"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneFamilyEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Family") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("RuneFamily"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RunePageEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("RunePage"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillTypeEntity", b => + { + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Type"); + + b.ToTable("SkillType"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionSkinName") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionSkinName"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Skin"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionClassEntity", "Class") + .WithMany() + .HasForeignKey("ClassId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Class"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.RuneFamilyEntity", "Family") + .WithMany() + .HasForeignKey("FamilyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("Family"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "ChampionSkin") + .WithMany() + .HasForeignKey("ChampionSkinName"); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("ChampionSkin"); + + b.Navigation("Image"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/EntityFrameworkLOL/Migrations/20230208161248_MigrationWallah4.cs b/Sources/EntityFrameworkLOL/Migrations/20230208161248_MigrationWallah4.cs new file mode 100644 index 0000000..2f96331 --- /dev/null +++ b/Sources/EntityFrameworkLOL/Migrations/20230208161248_MigrationWallah4.cs @@ -0,0 +1,223 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EntityFrameworkLOL.Migrations +{ + /// + public partial class MigrationWallah4 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Category", + columns: table => new + { + Category = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Category", x => x.Category); + }); + + migrationBuilder.CreateTable( + name: "ChampionClass", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Class = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ChampionClass", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Image", + columns: table => new + { + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Image", x => x.Base64); + }); + + migrationBuilder.CreateTable( + name: "RuneFamily", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Family = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RuneFamily", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "RunePage", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RunePage", x => x.Name); + }); + + migrationBuilder.CreateTable( + name: "SkillType", + columns: table => new + { + Type = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SkillType", x => x.Type); + }); + + migrationBuilder.CreateTable( + name: "Champion", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Bio = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + ClassId = table.Column(type: "INTEGER", nullable: false), + ImageBase64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champion", x => x.Name); + table.ForeignKey( + name: "FK_Champion_ChampionClass_ClassId", + column: x => x.ClassId, + principalTable: "ChampionClass", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Champion_Image_ImageBase64", + column: x => x.ImageBase64, + principalTable: "Image", + principalColumn: "Base64", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Rune", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + ImageBase64 = table.Column(type: "TEXT", nullable: true), + FamilyId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Rune", x => x.Name); + table.ForeignKey( + name: "FK_Rune_Image_ImageBase64", + column: x => x.ImageBase64, + principalTable: "Image", + principalColumn: "Base64"); + table.ForeignKey( + name: "FK_Rune_RuneFamily_FamilyId", + column: x => x.FamilyId, + principalTable: "RuneFamily", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Skin", + columns: table => new + { + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false), + ImageBase64 = table.Column(type: "TEXT", nullable: true), + ChampionSkinName = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skin", x => x.Name); + table.ForeignKey( + name: "FK_Skin_Champion_ChampionSkinName", + column: x => x.ChampionSkinName, + principalTable: "Champion", + principalColumn: "Name"); + table.ForeignKey( + name: "FK_Skin_Image_ImageBase64", + column: x => x.ImageBase64, + principalTable: "Image", + principalColumn: "Base64"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Champion_ClassId", + table: "Champion", + column: "ClassId"); + + migrationBuilder.CreateIndex( + name: "IX_Champion_ImageBase64", + table: "Champion", + column: "ImageBase64"); + + migrationBuilder.CreateIndex( + name: "IX_Rune_FamilyId", + table: "Rune", + column: "FamilyId"); + + migrationBuilder.CreateIndex( + name: "IX_Rune_ImageBase64", + table: "Rune", + column: "ImageBase64"); + + migrationBuilder.CreateIndex( + name: "IX_Skin_ChampionSkinName", + table: "Skin", + column: "ChampionSkinName"); + + migrationBuilder.CreateIndex( + name: "IX_Skin_ImageBase64", + table: "Skin", + column: "ImageBase64"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Category"); + + migrationBuilder.DropTable( + name: "Rune"); + + migrationBuilder.DropTable( + name: "RunePage"); + + migrationBuilder.DropTable( + name: "SkillType"); + + migrationBuilder.DropTable( + name: "Skin"); + + migrationBuilder.DropTable( + name: "RuneFamily"); + + migrationBuilder.DropTable( + name: "Champion"); + + migrationBuilder.DropTable( + name: "ChampionClass"); + + migrationBuilder.DropTable( + name: "Image"); + } + } +} diff --git a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs index 59fd766..85b39a6 100644 --- a/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs +++ b/Sources/EntityFrameworkLOL/Migrations/SQLiteContextModelSnapshot.cs @@ -16,6 +16,69 @@ namespace EntityFrameworkLOL.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + modelBuilder.Entity("EntityFrameworkLOL.Entities.CategoryEntity", b => + { + b.Property("Category") + .HasColumnType("INTEGER"); + + b.HasKey("Category"); + + b.ToTable("Category"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionClassEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("ChampionClass"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ClassId") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.HasIndex("ClassId"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Champion"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ImageEntity", b => + { + b.Property("Base64") + .HasColumnType("TEXT"); + + b.HasKey("Base64"); + + b.ToTable("Image"); + }); + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => { b.Property("Name") @@ -25,10 +88,136 @@ namespace EntityFrameworkLOL.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("FamilyId") + .HasColumnType("INTEGER"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + b.HasKey("Name"); + b.HasIndex("FamilyId"); + + b.HasIndex("ImageBase64"); + b.ToTable("Rune"); }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneFamilyEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Family") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("RuneFamily"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RunePageEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Name"); + + b.ToTable("RunePage"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkillTypeEntity", b => + { + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Type"); + + b.ToTable("SkillType"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("ChampionSkinName") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageBase64") + .HasColumnType("TEXT"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionSkinName"); + + b.HasIndex("ImageBase64"); + + b.ToTable("Skin"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.ChampionEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionClassEntity", "Class") + .WithMany() + .HasForeignKey("ClassId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Class"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.RuneEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.RuneFamilyEntity", "Family") + .WithMany() + .HasForeignKey("FamilyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("Family"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("EntityFrameworkLOL.Entities.SkinEntity", b => + { + b.HasOne("EntityFrameworkLOL.Entities.ChampionEntity", "ChampionSkin") + .WithMany() + .HasForeignKey("ChampionSkinName"); + + b.HasOne("EntityFrameworkLOL.Entities.ImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageBase64"); + + b.Navigation("ChampionSkin"); + + b.Navigation("Image"); + }); #pragma warning restore 612, 618 } } diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index 7271191..be3799b 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -8,14 +8,14 @@ class Program { static void Main(string[] args) { - /*ChampionEntity akali = new ChampionEntity {Name="Akali"}; - ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox" }; - ChampionEntity ahri = new ChampionEntity { Name = "Ahri" }; - ChampionEntity bard = new ChampionEntity { Name = "Bard" }; - ChampionEntity alistar = new ChampionEntity { Name = "Alistar" }; - ChampionEntity akshan = new ChampionEntity { Name = "Akshan" }; + ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "" }; + ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox", Bio = "" }; + ChampionEntity ahri = new ChampionEntity { Name = "Ahri", Bio = "" }; + ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "" }; + ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "" }; + ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "" }; - using (var context = new ChampionContext()) + using (var context = new SQLiteContext()) { // Crée des champions et les insère dans la base Console.WriteLine("Creates and inserts new Champions"); @@ -27,11 +27,11 @@ class Program context.Add(akshan); context.SaveChanges(); Console.WriteLine("Creates and executes a query retrieving the first Champion of the database whose name starts with an \"A\":"); - var aChampion = context.Champions + var aChampion = context.Champion .Where(c => c.Name.StartsWith("A")) .First(); - Console.WriteLine($"{aChampion.Name} (with bio : {aChampion.Bio}"); - }*/ + Console.WriteLine($"{aChampion.Name} (with bio : \"{aChampion.Bio}\")"); + } RuneEntity conqueror = new RuneEntity { Name = "Conqueror", Description = "" }; RuneEntity thriumph = new RuneEntity { Name = "Thriumph", Description = "" }; @@ -40,7 +40,7 @@ class Program RuneEntity laststand = new RuneEntity { Name = "Last Stand", Description = "" }; RuneEntity laststand2 = new RuneEntity { Name = "Last Stand 2", Description = "" }; - using (var context = new RuneContext()) + using (var context = new SQLiteContext()) { // Crée des Runes et les insère dans la base Console.WriteLine("Creates and inserts new Runes"); @@ -55,17 +55,17 @@ class Program var lRune = context.Rune .Where(r => r.Name.StartsWith("L")) .First(); - Console.WriteLine($"{lRune.Name} (with Description : {lRune.Description}"); + Console.WriteLine($"{lRune.Name} (with Description : \"{lRune.Description}\")"); } - /*SkinEntity stinger = new SkinEntity { Name = "Stinger", Description = "" }; + SkinEntity stinger = new SkinEntity { Name = "Stinger", Description = "" }; SkinEntity infernal = new SkinEntity { Name = "Infernal", Description = "" }; SkinEntity allStar = new SkinEntity { Name = "All-Star", Description = "" }; SkinEntity justicar = new SkinEntity { Name = "Justicar", Description = "" }; SkinEntity mecha = new SkinEntity { Name = "Mecha", Description = "" }; SkinEntity seaHunter = new SkinEntity { Name = "Sea Hunter", Description = "" }; - using (var context = new SkinContext()) + using (var context = new SQLiteContext()) { // Crée des Skins et les insère dans la base Console.WriteLine("Creates and inserts new Skins"); @@ -80,18 +80,28 @@ class Program var iSkin = context.Skin .Where(s => s.Name.StartsWith("I")) .First(); - Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + Console.WriteLine($"{iSkin.Name} (with Description : \"{iSkin.Description}\")"); Console.WriteLine("Updates the name of the Infernal Skin"); - iSkin.Name = "Infernal of Hell (Wallah)"; + iSkin.Description = "Hella Infernal (Wallah)"; context.SaveChanges(); - Console.WriteLine($"{iSkin.Name} (with Description : {iSkin.Description}"); + Console.WriteLine($"{iSkin.Name} (with Description : \"{iSkin.Description}\")"); Console.WriteLine("Deletes one item from the database"); var droid = context.Skin .SingleOrDefault(s => s.Name.Equals("Infernal")); context.Remove(droid); context.SaveChanges(); - }*/ + } + + using (var context = new SQLiteContext()) + { + foreach (var c in context.Champion) + { + c.Bio = $"{c.Name}"; + Console.WriteLine($"{c.Name} - {c.Bio}"); + } + context.SaveChanges(); + } } } \ No newline at end of file