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

master
Louwar 2 years ago
parent bb3dc50dd0
commit e40792b45b

@ -2,5 +2,6 @@
{
public class RuneMapper
{
// TO DO
}
}

@ -2,5 +2,6 @@
{
public class RunePageMapper
{
// TO DO
}
}

@ -23,7 +23,6 @@ namespace EFMapping
Characteristics = Champ.Characteristics.Select(Charac => Charac.toEF(EfChampion, context)).ToList()
};
}
return EfChampion;
@ -31,7 +30,7 @@ namespace EFMapping
public static Champion toModel(this EFChampion EFChamp)
{
var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, "", EFChamp.Bio);
var champion = new Champion(EFChamp.Name, EFChamp.Class, EFChamp.Icon, EFChamp.Image.Base64, 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;

@ -2,6 +2,7 @@
using Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -25,7 +26,13 @@ namespace EFMapping
return EfCharacteristics;
}
public static Tuple<string, int> toModel(this EFCharacteristics charac)
=> new(charac.Name, charac.Value);
public static ReadOnlyDictionary<string, int> toModel(this EFCharacteristics charac)
{
var dict = new Dictionary<string, int>
{
{ charac.Name, charac.Value }
};
return new(dict);
}
}
}

@ -10,7 +10,19 @@ namespace EFMapping
{
public static class EFLargeImageMapper
{
public static EFLargeImage toEF(this LargeImage LargeImage) => new EFLargeImage { Id = Guid.NewGuid(), Base64 = LargeImage.Base64 };
public static EFLargeImage toEF(this LargeImage LargeImage, SQLiteContext context)
{
var EfLargeImage = context.LargeImages.Find(LargeImage.Base64);
if (EfLargeImage == null)
{
return new()
{
Id = Guid.NewGuid(),
Base64 = LargeImage.Base64
};
}
return EfLargeImage;
}
public static LargeImage toModel(this EFLargeImage EFlargeImage) => new LargeImage(EFlargeImage.Base64);
}
}

@ -10,7 +10,7 @@ namespace EFMapping
{
public static class EFSkillMapper
{
public static EFSkill toEF(this Skill skill, EFChampion champion, SQLiteContext context)
public static EFSkill toEF(this Skill skill, SQLiteContext context)
{
var EfSkill = context.Skills.Find(skill.Name);
if (EfSkill == null)
@ -19,16 +19,11 @@ namespace EFMapping
{
Name = skill.Name,
Description = skill.Description,
Type = skill.Type,
Champion = new List<EFChampion>() { champion }
Type = skill.Type
};
}
EfSkill!.Champions?.Add(champion);
return EfSkill;
}
public static Skill toModel(this EFSkill skill)
=> new(skill.Name, skill.Type, skill.Description);
public static Skill toModel(this EFSkill skill)=> new(skill.Name, skill.Type, skill.Description);
}
}

@ -10,7 +10,10 @@ namespace EFMapping
{
public static class EFSkinMapper
{
public static EFSkin toEF(this Skin skin, SQLiteContext? context = null)
public static EFSkin toEF(this Skin skin, SQLiteContext context)
{
var EfSkin = context.Skins.Find(skin.Name);
if (EfSkin == null)
{
return new()
{
@ -20,10 +23,12 @@ namespace EFMapping
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),
Champion = context?.Champions.Find(skin.Champion.Name) ?? skin.Champion.toEF(context)
};
}
return EfSkin;
}
public static Skin toModel(this EFSkin Skin)=> new(Skin.Name, Skin.Champion.toModel(), Skin.Price, null, Skin.Description);
public static Skin toModel(this EFSkin Skin)=> new(Skin.Name, Skin.Champion.toModel(), Skin.Price, Skin.Icon, Skin.Image.Base64, Skin.Description);
}
}

@ -2,6 +2,7 @@
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;

@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EFlib.Migrations
{
[DbContext(typeof(SQLiteContext))]
[Migration("20230321114141_myMigration")]
[Migration("20230322115837_myMigration")]
partial class myMigration
{
/// <inheritdoc />
@ -65,7 +65,7 @@ namespace EFlib.Migrations
b.HasIndex("NameChampion");
b.ToTable("EFCharacteristics");
b.ToTable("Characteristics");
});
modelBuilder.Entity("EFlib.EFLargeImage", b =>
@ -80,7 +80,7 @@ namespace EFlib.Migrations
b.HasKey("Id");
b.ToTable("EFLargeImage");
b.ToTable("LargeImages");
});
modelBuilder.Entity("EFlib.EFSkill", b =>

@ -12,7 +12,7 @@ namespace EFlib.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "EFLargeImage",
name: "LargeImages",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
@ -20,7 +20,7 @@ namespace EFlib.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_EFLargeImage", x => x.Id);
table.PrimaryKey("PK_LargeImages", x => x.Id);
});
migrationBuilder.CreateTable(
@ -37,15 +37,15 @@ namespace EFlib.Migrations
{
table.PrimaryKey("PK_Champions", x => x.Name);
table.ForeignKey(
name: "FK_Champions_EFLargeImage_ImageId",
name: "FK_Champions_LargeImages_ImageId",
column: x => x.ImageId,
principalTable: "EFLargeImage",
principalTable: "LargeImages",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "EFCharacteristics",
name: "Characteristics",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 250, nullable: false),
@ -54,9 +54,9 @@ namespace EFlib.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_EFCharacteristics", x => x.Name);
table.PrimaryKey("PK_Characteristics", x => x.Name);
table.ForeignKey(
name: "FK_EFCharacteristics_Champions_NameChampion",
name: "FK_Characteristics_Champions_NameChampion",
column: x => x.NameChampion,
principalTable: "Champions",
principalColumn: "Name",
@ -103,9 +103,9 @@ namespace EFlib.Migrations
principalColumn: "Name",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Skins_EFLargeImage_ImageId",
name: "FK_Skins_LargeImages_ImageId",
column: x => x.ImageId,
principalTable: "EFLargeImage",
principalTable: "LargeImages",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -116,8 +116,8 @@ namespace EFlib.Migrations
column: "ImageId");
migrationBuilder.CreateIndex(
name: "IX_EFCharacteristics_NameChampion",
table: "EFCharacteristics",
name: "IX_Characteristics_NameChampion",
table: "Characteristics",
column: "NameChampion");
migrationBuilder.CreateIndex(
@ -140,7 +140,7 @@ namespace EFlib.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "EFCharacteristics");
name: "Characteristics");
migrationBuilder.DropTable(
name: "Skills");
@ -152,7 +152,7 @@ namespace EFlib.Migrations
name: "Champions");
migrationBuilder.DropTable(
name: "EFLargeImage");
name: "LargeImages");
}
}
}

@ -62,7 +62,7 @@ namespace EFlib.Migrations
b.HasIndex("NameChampion");
b.ToTable("EFCharacteristics");
b.ToTable("Characteristics");
});
modelBuilder.Entity("EFlib.EFLargeImage", b =>
@ -77,7 +77,7 @@ namespace EFlib.Migrations
b.HasKey("Id");
b.ToTable("EFLargeImage");
b.ToTable("LargeImages");
});
modelBuilder.Entity("EFlib.EFSkill", b =>

Binary file not shown.
Loading…
Cancel
Save