diff --git a/WebApi/Entities/QuestionEntity.cs b/WebApi/Entities/QuestionEntity.cs new file mode 100644 index 0000000..38605d0 --- /dev/null +++ b/WebApi/Entities/QuestionEntity.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entities +{ + public class QuestionEntity + { + public int Id { get; set; } + public string Content { get; set; } + public int difficuty { get; set; } + public int NbFalls { get; set; } + public int IdChapter { get; set; } + + [ForeignKey(nameof(AnswerEntity))] + public int IdAnswerGood { get; set; } + } +} diff --git a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs new file mode 100644 index 0000000..ce9a13c --- /dev/null +++ b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs @@ -0,0 +1,94 @@ +using DTOs; +using Entities; +using Model; + +namespace ExtensionsClassLibrairie +{ + public static class AnswerExtensionMethods + { + + /// + /// convet a dto answer into a model answer + /// + /// the dto answer to convert + /// the model answer that correspond + public static Answer ToModel(this AnswerDto a) + { + return new Answer(a.Content, a.Id); + } + + /// + /// convet an entity answer into a model answer + /// + /// the entity answer to convert + /// the model answer that correspond + public static Answer ToModel(this AnswerEntity a) + { + return new Answer(a.Content, a.Id); + } + + /// + /// convet a model answer into an entity answer + /// + /// the model answer to convert + /// the entity answer that correspond + public static AnswerEntity ToEntity(this Answer a) + { + return new AnswerEntity + { + Id = a.Id, + Content = a.Content + }; + } + + /// + /// convet a dto answer into an entity answer + /// + /// the dto answer to convert + /// the entity answer that correspond + public static AnswerEntity ToEntity(this AnswerDto a) + { + return new AnswerEntity + { + Id = a.Id, + Content = a.Content + }; + } + + /// + /// convet a model answer into a dto answer + /// + /// the model answer to convert + /// the dto answer that correspond + public static AnswerDto ToDto(this Answer a) + { + return new AnswerDto(a.Content, a.Id); + } + + /// + /// convet an entity answer into a dto answer + /// + /// the entity answer to convert + /// the dto answer that correspond + public static AnswerDto ToDto(this AnswerEntity a) + { + return new AnswerDto(a.Content, a.Id); + } + + /// + /// equality protocole + /// + /// an object + /// + /// 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 + /// + public static bool Equals(this AnswerEntity a, object? obj) + { + return obj != null && obj is AnswerEntity other + && other.Content == a.Content; + } + } +} diff --git a/WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj b/WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj new file mode 100644 index 0000000..0c6b8fd --- /dev/null +++ b/WebApi/ExtensionsClassLibrairie/ExtensionsClassLibrairie.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + +