From 813dccecb9e1c0b5976472da48ebdcecf26fa035 Mon Sep 17 00:00:00 2001 From: Damien Nortier Date: Mon, 11 Mar 2024 12:38:23 +0100 Subject: [PATCH] =?UTF-8?q?perf=20:=20modification=20des=20m=C3=A9thodes?= =?UTF-8?q?=20d'extension?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdministratorExtensionMethods.cs | 5 +++++ .../AnswerExtensionMethods.cs | 8 ++++---- .../LobbyExtensionMethods.cs | 6 ++---- .../QuestionExtensionMethods.cs | 12 ++++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs index fb74830..9204c25 100644 --- a/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs @@ -31,5 +31,10 @@ namespace ExtensionsClassLibrairie => a.ToModel().ToDto(); public static AdministratorEntity ToEntity(this AdministratorDto a) => a.ToModel().ToEntity(); + + public static string ToString(this AdministratorDto dto) + { + return $"{dto.Id} : {dto.Username}"; + } } } diff --git a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs index 753634f..1d25173 100644 --- a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs @@ -18,13 +18,13 @@ namespace ExtensionsClassLibrairie { // conversion methods public static Answer ToModel(this AnswerEntity a) - => new Answer(a.Content, a.Question?.ToModel(), a.Id); + => new Answer(a.Content, a.IdQuestion , a.Id); public static Answer ToModel(this AnswerDto a) - => new Answer(a.Content, a.Question?.ToModel(), a.Id); + => new Answer(a.Content, a.IdQuestion, a.Id); public static AnswerDto ToDto(this Answer a) - => new AnswerDto { Id = a.Id, Content = a.Content, Question = a.Question?.ToDto(), IdQuestion = a.IdQuestion }; + => new AnswerDto { Id = a.Id, Content = a.Content, 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 }; + => new AnswerEntity { Id = a.Id, Content = a.Content, IdQuestion = a.IdQuestion }; // reuse other methods public static AnswerDto ToDto(this AnswerEntity a) diff --git a/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs index f781848..a6bae8e 100644 --- a/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs @@ -17,14 +17,13 @@ namespace ExtensionsClassLibrairie { // conversion methods public static Lobby ToModel(this LobbyEntity l) - => new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id); + => new Lobby(l.Name, l.IdCreator, l.Password, l.NbPlayers, l.Id); public static Lobby ToModel(this LobbyDto l) - => new Lobby(l.Name, l.Creator.ToModel(), l.Password, l.NbPlayers, l.Id); + => new Lobby(l.Name, l.IdCreator, l.Password, l.NbPlayers, l.Id); public static LobbyDto ToDto(this Lobby l) => new LobbyDto { Id = l.Id, - Creator = l.Creator.ToDto(), IdCreator = l.IdCreator, Name = l.Name, Password = l.Password, @@ -34,7 +33,6 @@ namespace ExtensionsClassLibrairie => new LobbyEntity { Id = l.Id, - Creator = l.Creator.ToEntity(), IdCreator = l.IdCreator, Name = l.Name, Password = l.Password, diff --git a/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs index b34308f..8088355 100644 --- a/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs +++ b/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs @@ -19,24 +19,24 @@ namespace ExtensionsClassLibrairie // conversion methods public static Question ToModel(this QuestionEntity q) { - var tmp = new Question(q.Content, q.Chapter?.ToModel(), q.Id, q.AnswerGood?.ToModel()); + var tmp = new Question(q.Content, q.IdChapter, q.Id, q.IdAnswerGood); tmp.Difficulty = q.Difficulty; tmp.NbFalls = q.NbFalls; return tmp; } public static Question ToModel(this QuestionDto q) { - var tmp = new Question(q.Content, q.Chapter?.ToModel(), q.Id, q.AnswerGood?.ToModel()); + var tmp = new Question(q.Content, q.IdChapter, q.Id, q.IdAnswerGood); tmp.Difficulty = q.Difficulty; tmp.NbFalls = q.NbFalls; return tmp; } public static QuestionDto ToDto(this Question q) - => new QuestionDto { Id = q.Id, Content = q.Content, AnswerGood = q.AnswerGood?.ToDto(), - Chapter = q.Chapter?.ToDto(), Difficulty = q.Difficulty, NbFalls = q.NbFalls }; + => new QuestionDto { Id = q.Id, Content = q.Content, IdAnswerGood = q.IdAnswerGood, + IdChapter = q.IdChapter, Difficulty = q.Difficulty, NbFalls = q.NbFalls }; public static QuestionEntity ToEntity(this Question q) - => new QuestionEntity { Id = q.Id, Content = q.Content, AnswerGood = q.AnswerGood?.ToEntity(), - Chapter = q.Chapter?.ToEntity(), Difficulty = q.Difficulty, NbFalls = q.NbFalls }; + => new QuestionEntity { Id = q.Id, Content = q.Content, IdAnswerGood = q.IdAnswerGood, + IdChapter = q.IdChapter, Difficulty = q.Difficulty, NbFalls = q.NbFalls }; // reuse other methods public static QuestionDto ToDto(this QuestionEntity q)