You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4 KiB

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)
{
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;
}
}
}