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 { Content = a.Content, Id = 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 { Content = a.Content, Id = 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; } } }