Update EF
continuous-integration/drone/push Build is failing Details

master
Louwar 2 years ago
parent 9cb925f7e0
commit 0445d78110

@ -1,61 +0,0 @@
using EFlib;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFManager
{
public static class ManagerTranslate
{
// Champion
public static EFChampion toEF(this Champion Champ, SQLiteContext context)
{
EFChampion? EfChampion = context.Champions.Find(Champ.Name);
if (EfChampion == null)
{
EfChampion = new()
{
Name = Champ.Name,
Bio = Champ.Bio,
Icon = Champ.Icon,
Class = Champ.Class,
Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 },
};
EfChampion.Skills = Champ.Skills.Select(Skill => Skill.toEF(EfChampion, context)).ToList();
EfChampion.Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList();
}
return EfChampion;
}
public static Champion toModel(this EFChampion EFChamp)
{
var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio);
if (EFChamp.Skills != null) foreach (var s in EFChamp.Skills) { champion.AddSkill(skill.toModel()); }
if (EFChamp.Characteristics != null) foreach (var c in EFChamp.Characteristics) { champion.AddCharacteristics(c.toModel()); }
return champion;
}
// Characteristics
// Skin
public static EFSkin toEF(this Skin Skin) => new EFSkin { Name = Skin.Name, Description = Skin.Description, Icon = Skin.Icon, Price = Skin.Price };
public static Skin toModel(this EFSkin EFSkin) => new Skin(EFSkin.Name, EFSkin.Champion.toModel());
// Skill
// LargeImage
public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 };
public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64);
// Rune
// RunePage
}
}

@ -1,8 +1,40 @@
namespace EFMapping using EFlib;
using Model;
namespace EFMapping
{
public static class EFChampionMapper
{
public static EFChampion toEF(this Champion Champ, SQLiteContext context)
{
EFChampion? EfChampion = context.Champions.Find(Champ.Name);
if (EfChampion == null)
{ {
public class EFChampionMapper EfChampion = new()
{ {
Name = Champ.Name,
Bio = Champ.Bio,
Icon = Champ.Icon,
Class = Champ.Class,
Image = new() { Id = Guid.NewGuid(), Base64 = Champ.Image.Base64 },
Skills = Champ.Skills.Select(Skill => Skill.toEF(EfChampion, context)).ToList(),
Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList()
};
} }
return EfChampion;
}
public static Champion toModel(this EFChampion EFChamp)
{
var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio);
if (EFChamp.Skills != null) foreach (var skill in EFChamp.Skills) { champion.AddSkill(skill.toModel()); }
if (EFChamp.Characteristics != null) foreach (var charac in EFChamp.Characteristics) { champion.AddCharacteristics(charac.toModel()); }
return champion;
}
}
} }

@ -0,0 +1,31 @@
using EFlib;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFMapping
{
public static class EFCharacteristicsMapper
{
public static EFCharacteristics toEF(this KeyValuePair<string, int> item, EFChampion champion, SQLiteContext context)
{
var charac = context.Characteristics.Find(item.Key, champion.Name);
if (charac == null)
{
return new()
{
Name = item.Key,
Value = item.Value,
NameChampion = champion.Name
};
}
return charac;
}
public static Tuple<string, int> toModel(this EFCharacteristics charac)
=> new(charac.Name, charac.Value);
}
}

@ -0,0 +1,16 @@
using EFlib;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EFMapping
{
public static class EFLargeImageMapper
{
public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 };
public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64);
}
}

@ -6,4 +6,9 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EFlib\EFlib.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project> </Project>

@ -8,5 +8,6 @@ namespace EFMapping
{ {
public class EFRuneMapper public class EFRuneMapper
{ {
// TO DO
} }
} }

@ -8,5 +8,6 @@ namespace EFMapping
{ {
public class EFRunePageMapper public class EFRunePageMapper
{ {
// TO DO
} }
} }

@ -1,4 +1,6 @@
using System; using EFlib;
using Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,7 +8,27 @@ using System.Threading.Tasks;
namespace EFMapping namespace EFMapping
{ {
public class EFSkillMapper public static class EFSkillMapper
{ {
public static EFSkill toEF(this Skill skill, EFChampion champion, SQLiteContext context)
{
var EfSkill = context.Skills.Find(skill.Name);
if (EfSkill == null)
{
return new()
{
Name = skill.Name,
Description = skill.Description,
Type = skill.Type,
Champion = new List<EFChampion>() { champion }
};
}
EfSkill!.Champions?.Add(champion);
return EfSkill;
}
public static Skill toModel(this EFSkill skill)
=> new(skill.Name, skill.Type, skill.Description);
} }
} }

@ -1,4 +1,6 @@
using System; using EFlib;
using Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,7 +8,22 @@ using System.Threading.Tasks;
namespace EFMapping namespace EFMapping
{ {
public class EFSkinMapper public static class EFSkinMapper
{ {
public static EFSkin toEF(this Skin skin, SQLiteContext? context = null)
{
return new()
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price,
Image = new() { Id = Guid.NewGuid(), Base64 = skin.Image.Base64 },
NameChampion = skin.Champion.Name,
Champion = context?.Champions.Find(skin.Champion.Name) ?? skin.Champion.toEF(context),
};
}
public static Skin toModel(this EFSkin Skin)=> new(Skin.Name, Skin.Champion.toModel(), Skin.Price, null, Skin.Description);
} }
} }

@ -12,7 +12,7 @@ namespace EFlib
{ {
/**** Only Attributs ****/ /**** Only Attributs ****/
[Key] [Key]
[MaxLength(256)] [MaxLength(250)]
public string Name { get; set; } public string Name { get; set; }
[MaxLength(500)] [MaxLength(500)]

@ -11,14 +11,13 @@ namespace EFlib
public class EFCharacteristics public class EFCharacteristics
{ {
[Key] [Key]
public int Id { get; set; } [MaxLength(250)]
public string Name { get; set; } public string Name { get; set; }
[Required]
public int Value { get; set; } public int Value { get; set; }
[Required]
// Clé étrangère vers l'entité parente public string NameChampion { get; set; }
public EFChampion EFChampion { get; set; } [ForeignKey("NameChampion")]
[ForeignKey("EFChampion")] public EFChampion Champion { get; set; }
public string EFChampionName { get; set; }
} }
} }

@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EFlib.Migrations namespace EFlib.Migrations
{ {
[DbContext(typeof(SQLiteContext))] [DbContext(typeof(SQLiteContext))]
[Migration("20230318182850_myMigrations")] [Migration("20230321114141_myMigration")]
partial class myMigrations partial class myMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -23,7 +23,7 @@ namespace EFlib.Migrations
modelBuilder.Entity("EFlib.EFChampion", b => modelBuilder.Entity("EFlib.EFChampion", b =>
{ {
b.Property<string>("Name") b.Property<string>("Name")
.HasMaxLength(256) .HasMaxLength(250)
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Bio") b.Property<string>("Bio")
@ -50,24 +50,20 @@ namespace EFlib.Migrations
modelBuilder.Entity("EFlib.EFCharacteristics", b => modelBuilder.Entity("EFlib.EFCharacteristics", b =>
{ {
b.Property<int>("Id") b.Property<string>("Name")
.ValueGeneratedOnAdd() .HasMaxLength(250)
.HasColumnType("INTEGER");
b.Property<string>("EFChampionName")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Name") b.Property<string>("NameChampion")
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("Value") b.Property<int>("Value")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("Id"); b.HasKey("Name");
b.HasIndex("EFChampionName"); b.HasIndex("NameChampion");
b.ToTable("EFCharacteristics"); b.ToTable("EFCharacteristics");
}); });
@ -154,13 +150,13 @@ namespace EFlib.Migrations
modelBuilder.Entity("EFlib.EFCharacteristics", b => modelBuilder.Entity("EFlib.EFCharacteristics", b =>
{ {
b.HasOne("EFlib.EFChampion", "EFChampion") b.HasOne("EFlib.EFChampion", "Champion")
.WithMany("Characteristics") .WithMany("Characteristics")
.HasForeignKey("EFChampionName") .HasForeignKey("NameChampion")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("EFChampion"); b.Navigation("Champion");
}); });
modelBuilder.Entity("EFlib.EFSkill", b => modelBuilder.Entity("EFlib.EFSkill", b =>

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace EFlib.Migrations namespace EFlib.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class myMigrations : Migration public partial class myMigration : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -27,7 +27,7 @@ namespace EFlib.Migrations
name: "Champions", name: "Champions",
columns: table => new columns: table => new
{ {
Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false), Name = table.Column<string>(type: "TEXT", maxLength: 250, nullable: false),
Bio = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false), Bio = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false), Icon = table.Column<string>(type: "TEXT", nullable: false),
Class = table.Column<int>(type: "INTEGER", nullable: false), Class = table.Column<int>(type: "INTEGER", nullable: false),
@ -48,18 +48,16 @@ namespace EFlib.Migrations
name: "EFCharacteristics", name: "EFCharacteristics",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(type: "INTEGER", nullable: false) Name = table.Column<string>(type: "TEXT", maxLength: 250, nullable: false),
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Value = table.Column<int>(type: "INTEGER", nullable: false), Value = table.Column<int>(type: "INTEGER", nullable: false),
EFChampionName = table.Column<string>(type: "TEXT", nullable: false) NameChampion = table.Column<string>(type: "TEXT", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_EFCharacteristics", x => x.Id); table.PrimaryKey("PK_EFCharacteristics", x => x.Name);
table.ForeignKey( table.ForeignKey(
name: "FK_EFCharacteristics_Champions_EFChampionName", name: "FK_EFCharacteristics_Champions_NameChampion",
column: x => x.EFChampionName, column: x => x.NameChampion,
principalTable: "Champions", principalTable: "Champions",
principalColumn: "Name", principalColumn: "Name",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -118,9 +116,9 @@ namespace EFlib.Migrations
column: "ImageId"); column: "ImageId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_EFCharacteristics_EFChampionName", name: "IX_EFCharacteristics_NameChampion",
table: "EFCharacteristics", table: "EFCharacteristics",
column: "EFChampionName"); column: "NameChampion");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Skills_EFChampionName", name: "IX_Skills_EFChampionName",

@ -20,7 +20,7 @@ namespace EFlib.Migrations
modelBuilder.Entity("EFlib.EFChampion", b => modelBuilder.Entity("EFlib.EFChampion", b =>
{ {
b.Property<string>("Name") b.Property<string>("Name")
.HasMaxLength(256) .HasMaxLength(250)
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Bio") b.Property<string>("Bio")
@ -47,24 +47,20 @@ namespace EFlib.Migrations
modelBuilder.Entity("EFlib.EFCharacteristics", b => modelBuilder.Entity("EFlib.EFCharacteristics", b =>
{ {
b.Property<int>("Id") b.Property<string>("Name")
.ValueGeneratedOnAdd() .HasMaxLength(250)
.HasColumnType("INTEGER");
b.Property<string>("EFChampionName")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Name") b.Property<string>("NameChampion")
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("Value") b.Property<int>("Value")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("Id"); b.HasKey("Name");
b.HasIndex("EFChampionName"); b.HasIndex("NameChampion");
b.ToTable("EFCharacteristics"); b.ToTable("EFCharacteristics");
}); });
@ -151,13 +147,13 @@ namespace EFlib.Migrations
modelBuilder.Entity("EFlib.EFCharacteristics", b => modelBuilder.Entity("EFlib.EFCharacteristics", b =>
{ {
b.HasOne("EFlib.EFChampion", "EFChampion") b.HasOne("EFlib.EFChampion", "Champion")
.WithMany("Characteristics") .WithMany("Characteristics")
.HasForeignKey("EFChampionName") .HasForeignKey("NameChampion")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("EFChampion"); b.Navigation("Champion");
}); });
modelBuilder.Entity("EFlib.EFSkill", b => modelBuilder.Entity("EFlib.EFSkill", b =>

@ -6,6 +6,8 @@ namespace EFlib
{ {
/**** Attributs ****/ /**** Attributs ****/
public DbSet<EFChampion> Champions { get; set; } public DbSet<EFChampion> Champions { get; set; }
public DbSet<EFCharacteristics> Characteristics { get; set; }
public DbSet<EFLargeImage> LargeImages { get; set; }
public DbSet<EFSkin> Skins { get; set; } public DbSet<EFSkin> Skins { get; set; }
public DbSet<EFSkill> Skills { get; set; } public DbSet<EFSkill> Skills { get; set; }

Binary file not shown.

@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestManagerEF", "Tests\Test
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFMapping", "EFMapping\EFMapping.csproj", "{0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -93,6 +95,10 @@ Global
{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Debug|Any CPU.Build.0 = Debug|Any CPU {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.ActiveCfg = Release|Any CPU {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.Build.0 = Release|Any CPU {F7B6A3D6-6C70-49DC-9D1D-4B70071EEF25}.Release|Any CPU.Build.0 = Release|Any CPU
{0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0952BCD7-09D2-4D24-BD8C-1F88BA8D66EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save