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.
3.01-QCM_MuscuMaths/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs

36 lines
1.2 KiB

using DTOs;
using Entities;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExtensionsClassLibrairie
{
/// <summary>
/// define some methods to manipulate entity, model and dto players :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
public static class PlayerExtensionMethods
{
// conversion methods
public static Player ToModel(this PlayerEntity p)
=> new Player(p.Nickname, p.HashedPassword, p.Id);
public static Player ToModel(this PlayerDto p)
=> new Player(p.Nickname, p.HashedPassword, p.Id);
public static PlayerDto ToDto(this Player p)
=> new PlayerDto { Id = p.Id, Nickname = p.Nickname, HashedPassword = p.HashedPassword};
public static PlayerEntity ToEntity(this Player p)
=> new PlayerEntity { Id = p.Id, Nickname = p.Nickname, HashedPassword = p.HashedPassword };
// reuse other methods
public static PlayerDto ToDto(this PlayerEntity p)
=> p.ToModel().ToDto();
public static PlayerEntity ToEntity(this PlayerDto p)
=> p.ToModel().ToEntity();
}
}