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.
58 lines
2.5 KiB
58 lines
2.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();
|
|
|
|
// equality protocols
|
|
public static bool Equals(this Administrator a1, Administrator a2)
|
|
=> a1.Username == a2.Username;
|
|
|
|
// reuse other methods
|
|
public static bool Equals(this Administrator a1, AdministratorDto a2)
|
|
=> a1.Equals(a2.ToModel());
|
|
public static bool Equals(this Administrator a1, AdministratorEntity a2)
|
|
=> a1.Equals(a2.ToModel());
|
|
public static bool Equals(this AdministratorDto a1, Administrator a2)
|
|
=> a1.ToModel().Equals(a2);
|
|
public static bool Equals(this AdministratorDto a1, AdministratorDto a2)
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
public static bool Equals(this AdministratorDto a1, AdministratorEntity a2)
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
public static bool Equals(this AdministratorEntity a1, Administrator a2)
|
|
=> a1.ToModel().Equals(a2);
|
|
public static bool Equals(this AdministratorEntity a1, AdministratorDto a2)
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
public static bool Equals(this AdministratorEntity a1, AdministratorEntity a2)
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
}
|
|
}
|