109 lines
3.5 KiB
C#

using Liber_Incantamentum.Application.DTOs.Filter;
using Liber_Incantamentum.Application.DTOs.General;
using Liber_Incantamentum.Application.Interfaces.Mappings;
using Liber_Incantamentum.Domain.Entities;
using Liber_Incantamentum.Domain.Filter;
using System.Collections;
namespace Liber_Incantamentum.Application.Services.Mappings
{
public class Mapper : IMapper
{
public MageFilter MapMageDtoFilterToMageFilterEntity(MageDtoFilter filter)
{
MageFilter entity = new MageFilter()
{
Id = filter.Id,
Name = filter.Name,
Rank = filter.Rank,
Specialisation = filter.Specialisation
};
return entity;
}
public Mage MapMageDtoToMageEntity(MageDto dto)
{
Mage entity = new Mage()
{
Name = dto.Name,
Rank = dto.Rank,
Specialisation = dto.Specialisation
};
return entity;
}
public MageDto MapMageEntityToMageDto(Mage entity)
{
MageDto dto = new MageDto()
{
Name = entity.Name,
Rank = entity.Rank,
Specialisation = entity.Specialisation
};
return dto;
}
public ICollection<MageDto>? MapMageEntityCollectionToMageDtoCollection(ICollection<Mage> collection)
{
ICollection<MageDto> MageDtoCollection = new List<MageDto>();
foreach(var entity in collection)
{
MageDto dto = new MageDto()
{
Id = entity.Id,
Name = entity.Name,
Rank = entity.Rank,
Specialisation = entity.Specialisation
};
MageDtoCollection.Add(dto);
}
return MageDtoCollection;
}
public ICollection<SpellDto>? MapSpellEntityCollectionToSpellDtoCollection(ICollection<Spell> collection)
{
ICollection<SpellDto> SpellDtoCollection = new List<SpellDto>();
foreach (var entity in collection)
{
SpellDto dto = new SpellDto()
{
Id = entity.Id,
Name = entity.Name,
Description = entity.Description,
Type = entity.Type,
CreationDate = entity.CreationDate,
Mage = MapMageEntityToMageDto(entity.Mage)
};
SpellDtoCollection.Add(dto);
}
return SpellDtoCollection;
}
public SpellFilter MapSpellDtoFilterToSpellFilterEntity(SpellDtoFilter dto)
{
SpellFilter entity = new SpellFilter()
{
Id = dto.Id,
Name = dto.Name,
Description = dto.Description,
Type = dto.Type,
CreationDate = dto.CreationDate,
Mage = MapMageDtoFilterToMageFilterEntity(dto.Mage)
};
return entity;
}
public Spell MapSpellDtoToSpellEntity(SpellDto dto)
{
Spell entity = new Spell()
{
Id = dto.Id,
Name = dto.Name,
Description = dto.Description,
Type = dto.Type,
CreationDate = dto.CreationDate,
Mage = MapMageDtoToMageEntity(dto.Mage)
};
return entity;
}
}
}