|
|
|
@ -1,102 +1,57 @@
|
|
|
|
|
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 answers :
|
|
|
|
|
/// convert model to DTO, model to Entity, ...
|
|
|
|
|
/// and equality protocols
|
|
|
|
|
/// </summary>
|
|
|
|
|
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>
|
|
|
|
|
// conversion methods
|
|
|
|
|
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>
|
|
|
|
|
=> new Answer(a.Content, a.Question?.ToModel(), a.Id);
|
|
|
|
|
public static Answer ToModel(this AnswerDto a)
|
|
|
|
|
=> new Answer(a.Content, a.Question?.ToModel(), a.Id);
|
|
|
|
|
public static AnswerDto ToDto(this Answer a)
|
|
|
|
|
{
|
|
|
|
|
return new AnswerDto
|
|
|
|
|
{
|
|
|
|
|
Content = a.Content,
|
|
|
|
|
Id = a.Id
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
=> new AnswerDto { Id = a.Id, Content = a.Content, Question = a.Question?.ToDto(), IdQuestion = a.IdQuestion };
|
|
|
|
|
public static AnswerEntity ToEntity(this Answer a)
|
|
|
|
|
=> new AnswerEntity { Id = a.Id, Content = a.Content, Question = a.Question?.ToEntity(), IdQuestion = a.IdQuestion };
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
// reuse other methods
|
|
|
|
|
public static AnswerDto ToDto(this AnswerEntity a)
|
|
|
|
|
{
|
|
|
|
|
return new AnswerDto
|
|
|
|
|
{
|
|
|
|
|
Content = a.Content,
|
|
|
|
|
Id = 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;
|
|
|
|
|
}
|
|
|
|
|
=> a.ToModel().ToDto();
|
|
|
|
|
public static AnswerEntity ToEntity(this AnswerDto a)
|
|
|
|
|
=> a.ToModel().ToEntity();
|
|
|
|
|
|
|
|
|
|
// equality protocols
|
|
|
|
|
public static bool Equals(this Answer a1, Answer a2)
|
|
|
|
|
=> a1.Content == a2.Content && a1.IdQuestion == a2.IdQuestion;
|
|
|
|
|
|
|
|
|
|
// reuse other methods
|
|
|
|
|
public static bool Equals(this Answer a1, AnswerDto a2)
|
|
|
|
|
=> a1.Equals(a2.ToModel());
|
|
|
|
|
public static bool Equals(this Answer a1, AnswerEntity a2)
|
|
|
|
|
=> a1.Equals(a2.ToModel());
|
|
|
|
|
public static bool Equals(this AnswerDto a1, Answer a2)
|
|
|
|
|
=> a1.ToModel().Equals(a2);
|
|
|
|
|
public static bool Equals(this AnswerDto a1, AnswerDto a2)
|
|
|
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
|
|
|
public static bool Equals(this AnswerDto a1, AnswerEntity a2)
|
|
|
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
|
|
|
public static bool Equals(this AnswerEntity a1, Answer a2)
|
|
|
|
|
=> a1.ToModel().Equals(a2);
|
|
|
|
|
public static bool Equals(this AnswerEntity a1, AnswerDto a2)
|
|
|
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
|
|
|
public static bool Equals(this AnswerEntity a1, AnswerEntity a2)
|
|
|
|
|
=> a1.ToModel().Equals(a2.ToModel());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|