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.
41 lines
1.5 KiB
41 lines
1.5 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 adminstrators :
|
|
/// convert model to DTO, model to Entity, ...
|
|
/// and equality protocols
|
|
/// </summary>
|
|
public static class AdministratorExtensionMethods
|
|
{
|
|
// conversion methods
|
|
public static Administrator ToModel(this AdministratorEntity a)
|
|
=> new Administrator(a.Username, a.HashedPassword, a.Id);
|
|
public static Administrator ToModel(this AdministratorDto a)
|
|
=> new Administrator(a.Username, a.HashedPassword, a.Id);
|
|
public static AdministratorDto ToDto(this Administrator a)
|
|
=> new AdministratorDto { Id = a.Id, HashedPassword = a.HashedPassword, Username = a.Username };
|
|
public static AdministratorEntity ToEntity(this Administrator a)
|
|
=> new AdministratorEntity { Id = a.Id, HashedPassword = a.HashedPassword, Username = a.Username };
|
|
|
|
// reuse other methods
|
|
public static AdministratorDto ToDto(this AdministratorEntity a)
|
|
=> a.ToModel().ToDto();
|
|
public static AdministratorEntity ToEntity(this AdministratorDto a)
|
|
=> a.ToModel().ToEntity();
|
|
|
|
public static string ToString(this AdministratorDto dto)
|
|
{
|
|
return $"{dto.Id} : {dto.Username}";
|
|
}
|
|
}
|
|
}
|