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.
League-of-Legends_Project/EntityFramework_LoL/Sources/EntityMappers/ChampionMapper.cs

41 lines
1.4 KiB

using Entities;
using EntityMappers;
using Model;
namespace EntityMapper
{
public static class ChampionMapper {
public static ChampionEntity ToEntity(this Champion item, LolDbContext context)
{
ChampionEntity championEntity = context.champions.Find(item.Name);
if (championEntity == null)
{
championEntity = new()
{
Name = item.Name,
Bio = item.Bio,
Icon = item.Icon,
Class = item.Class,
Image = new() { Base64 = item.Image.Base64 },
};
championEntity.Skills = item.Skills.Select(x => x.ToEntity(championEntity, context)).ToList();
championEntity.Characteristics = item.Characteristics.Select(x => x.ToEntity(championEntity, context)).ToList();
}
return championEntity;
}
public static Champion ToModel(this ChampionEntity entity)
{
var champion = new Champion(entity.Name, entity.Class, entity.Icon, "", entity.Bio);
if(entity.Skills!=null) foreach(var s in entity.Skills){champion.AddSkill(s.ToModel());}
if (entity.Characteristics != null) foreach (var c in entity.Characteristics){champion.AddCharacteristics(c.ToModel()); }
return champion;
}
}
}