|
|
|
@ -0,0 +1,94 @@
|
|
|
|
|
using DTOs;
|
|
|
|
|
using Entities;
|
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
|
|
namespace ExtensionsClassLibrairie
|
|
|
|
|
{
|
|
|
|
|
public static class AnswerExtensionMethods
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// convet a dto answer into a model answer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="a">the dto answer to convert</param>
|
|
|
|
|
/// <returns>the model answer that correspond</returns>
|
|
|
|
|
public static Answer ToModel(this AnswerDto a)
|
|
|
|
|
{
|
|
|
|
|
return new Answer(a.Content, a.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// convet an entity answer into a model answer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="a">the entity answer to convert</param>
|
|
|
|
|
/// <returns>the model answer that correspond</returns>
|
|
|
|
|
public static Answer ToModel(this AnswerEntity a)
|
|
|
|
|
{
|
|
|
|
|
return new Answer(a.Content, a.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// convet a model answer into an entity answer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="a">the model answer to convert</param>
|
|
|
|
|
/// <returns>the entity answer that correspond</returns>
|
|
|
|
|
public static AnswerEntity ToEntity(this Answer a)
|
|
|
|
|
{
|
|
|
|
|
return new AnswerEntity
|
|
|
|
|
{
|
|
|
|
|
Id = a.Id,
|
|
|
|
|
Content = a.Content
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// convet a dto answer into an entity answer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="a">the dto answer to convert</param>
|
|
|
|
|
/// <returns>the entity answer that correspond</returns>
|
|
|
|
|
public static AnswerEntity ToEntity(this AnswerDto a)
|
|
|
|
|
{
|
|
|
|
|
return new AnswerEntity
|
|
|
|
|
{
|
|
|
|
|
Id = a.Id,
|
|
|
|
|
Content = a.Content
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// convet a model answer into a dto answer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="a">the model answer to convert</param>
|
|
|
|
|
/// <returns>the dto answer that correspond</returns>
|
|
|
|
|
public static AnswerDto ToDto(this Answer a)
|
|
|
|
|
{
|
|
|
|
|
return new AnswerDto(a.Content, a.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// convet an entity answer into a dto answer
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="a">the entity answer to convert</param>
|
|
|
|
|
/// <returns>the dto answer that correspond</returns>
|
|
|
|
|
public static AnswerDto ToDto(this AnswerEntity a)
|
|
|
|
|
{
|
|
|
|
|
return new AnswerDto(a.Content, a.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// equality protocole
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">an object</param>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// true if the object is an AnswerEntity
|
|
|
|
|
/// and the two contents are equals
|
|
|
|
|
/// (we don't care about the id because
|
|
|
|
|
/// he's set by the database
|
|
|
|
|
/// </returns>
|
|
|
|
|
public static bool Equals(this AnswerEntity a, object? obj)
|
|
|
|
|
{
|
|
|
|
|
return obj != null && obj is AnswerEntity other
|
|
|
|
|
&& other.Content == a.Content;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|