diff --git a/WebApi/DTOs/AdministratorDto.cs b/WebApi/DTOs/AdministratorDto.cs
index a8057e0..6c6c1de 100644
--- a/WebApi/DTOs/AdministratorDto.cs
+++ b/WebApi/DTOs/AdministratorDto.cs
@@ -7,16 +7,16 @@ using System.Threading.Tasks;
namespace DTOs
{
+ ///
+ /// define a DTO for an administrator
+ /// properties :
+ /// Id : identifier in the database
+ /// Username : username for a administrator
+ /// HashedPassword : hash of the password of the administrator
+ ///
public class AdministratorDto
{
- ///
- /// define a DTO for an administrator
- /// properties :
- /// Id : identifier in the database
- /// Username : username for a administrator
- /// HashedPassword : hash of the password of the administrator
- ///
- public int? Id { get; set; }
+ public uint Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
diff --git a/WebApi/DTOs/AnswerDto.cs b/WebApi/DTOs/AnswerDto.cs
index 967330c..3e68657 100644
--- a/WebApi/DTOs/AnswerDto.cs
+++ b/WebApi/DTOs/AnswerDto.cs
@@ -3,20 +3,20 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DTOs
{
+ ///
+ /// define a DTO for an answer for a Question with Mutiple Choice
+ /// properties :
+ /// Id : identifier in the database
+ /// Content : content of the answer
+ /// IdQuestion : the id of the question which it answer to
+ /// Question : the question which it answer to
+ ///
public class AnswerDto
{
- ///
- /// define a DTO for an answer for a Question with Mutiple Choice
- /// properties :
- /// Id : identifier in the database
- /// Content : content of the answer
- /// IdQuestion : the id of the question which it answer to
- /// Question : the question which it answer to
- ///
- public int? Id { get; set; }
+ public uint Id { get; set; }
public string Content { get; set; } = null!;
- public int? IdQuestion { get; set; }
+ public uint? IdQuestion { get; set; }
- public QuestionDto Question { get; set; } = null!;
+ public QuestionDto? Question { get; set; } = null!;
}
}
diff --git a/WebApi/DTOs/ChapterDto.cs b/WebApi/DTOs/ChapterDto.cs
index e5c15ca..739f5eb 100644
--- a/WebApi/DTOs/ChapterDto.cs
+++ b/WebApi/DTOs/ChapterDto.cs
@@ -7,15 +7,15 @@ using System.Threading.Tasks;
namespace DTOs
{
+ ///
+ /// define a mathematical chapter or thematic
+ /// properties :
+ /// Id : identifier in the database
+ /// Name : name of the chapter
+ ///
public class ChapterDto
{
- ///
- /// define a mathematical chapter or thematic
- /// properties :
- /// Id : identifier in the database
- /// Name : name of the chapter
- ///
- public int? Id { get; set; }
+ public uint Id { get; set; }
public string Name { get; set; } = null!;
}
}
diff --git a/WebApi/DTOs/LobbyDto.cs b/WebApi/DTOs/LobbyDto.cs
index a82003a..455461b 100644
--- a/WebApi/DTOs/LobbyDto.cs
+++ b/WebApi/DTOs/LobbyDto.cs
@@ -8,22 +8,22 @@ using System.Threading.Tasks;
namespace DTOs
{
+ ///
+ /// define a lobby for QMC rapidity fight
+ /// properties :
+ /// Id : identifier of the lobby in the database
+ /// Name : name of the lobby
+ /// Password : password require to access at the lobby
+ /// IdCreator : identifier of the creator player
+ /// Creator : the creator player
+ ///
public class LobbyDto
{
- ///
- /// define a lobby for QMC rapidity fight
- /// properties :
- /// Id : identifier of the lobby in the database
- /// Name : name of the lobby
- /// Password : password require to access at the lobby
- /// IdCreator : identifier of the creator player
- /// Creator : the creator player
- ///
- public int? Id { get; set; }
+ public uint Id { get; set; }
public string Name { get; set; } = null!;
public string Password { get; set; } = null!;
- public int NbPlayers { get; set; }
- public int? IdCreator { get; set; }
+ public uint NbPlayers { get; set; }
+ public uint? IdCreator { get; set; }
public PlayerDto Creator { get; set; } = null!;
}
}
diff --git a/WebApi/DTOs/PlayerDto.cs b/WebApi/DTOs/PlayerDto.cs
index d0916c9..30e86f6 100644
--- a/WebApi/DTOs/PlayerDto.cs
+++ b/WebApi/DTOs/PlayerDto.cs
@@ -7,16 +7,16 @@ using System.Threading.Tasks;
namespace DTOs
{
+ ///
+ /// define a DTO for a player
+ /// properties :
+ /// Id : identifier in the database
+ /// Nickname : nickname for the player
+ /// HashedPassword : hashed of the password of the player
+ ///
public class PlayerDto
{
- ///
- /// define a DTO for a player
- /// properties :
- /// Id : identifier in the database
- /// Nickname : nickname for the player
- /// HashedPassword : hashed of the password of the player
- ///
- public int? Id { get; set; }
+ public uint Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
diff --git a/WebApi/DTOs/QuestionDto.cs b/WebApi/DTOs/QuestionDto.cs
index e62efd1..4782752 100644
--- a/WebApi/DTOs/QuestionDto.cs
+++ b/WebApi/DTOs/QuestionDto.cs
@@ -8,26 +8,26 @@ using System.Threading.Tasks;
namespace DTOs
{
+ ///
+ /// represent a mathematical question
+ /// properties :
+ /// Id : identifier of the question in the database
+ /// Content : the content of the question
+ /// Difficulty : difficulty (between 1 and 3 included) of the question
+ /// NbFails : number of time that people fail on this question
+ /// IdChapter : identifier of the chapter of the question
+ /// IdAnswerGood : identifier of the right answer to this question
+ /// Chapter : the chapter of the question
+ /// AnswerGood : the right answer to this question
+ ///
public class QuestionDto
{
- ///
- /// represent a mathematical question
- /// properties :
- /// Id : identifier of the question in the database
- /// Content : the content of the question
- /// Difficulty : difficulty (between 1 and 3 included) of the question
- /// NbFails : number of time that people fail on this question
- /// IdChapter : identifier of the chapter of the question
- /// IdAnswerGood : identifier of the right answer to this question
- /// Chapter : the chapter of the question
- /// AnswerGood : the right answer to this question
- ///
- public int? Id { get; set; }
+ public uint Id { get; set; }
public string Content { get; set; } = null!;
- public int Difficulty { get; set; }
- public int NbFalls { get; set; }
- public int? IdChapter { get; set; }
- public int? IdAnswerGood { get; set; }
+ public byte Difficulty { get; set; }
+ public uint NbFalls { get; set; }
+ public uint? IdChapter { get; set; }
+ public uint? IdAnswerGood { get; set; }
public ChapterDto? Chapter { get; set; }
public AnswerDto? AnswerGood { get; set; }
}
diff --git a/WebApi/Entities/AdministratorEntity.cs b/WebApi/Entities/AdministratorEntity.cs
index a4f0c89..e7a95bc 100644
--- a/WebApi/Entities/AdministratorEntity.cs
+++ b/WebApi/Entities/AdministratorEntity.cs
@@ -3,18 +3,18 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
+ ///
+ /// define an entity for an administrator
+ /// properties :
+ /// Id : identifier in the database
+ /// Username : username for a administrator
+ /// HashedPassword : hash of the password of the administrator
+ ///
[Table("Administrators")]
public class AdministratorEntity
{
- ///
- /// define an entity for an administrator
- /// properties :
- /// Id : identifier in the database
- /// Username : username for a administrator
- /// HashedPassword : hash of the password of the administrator
- ///
[Key]
- public uint? Id { get; set; }
+ public uint Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
diff --git a/WebApi/Entities/AnswerEntity.cs b/WebApi/Entities/AnswerEntity.cs
index 26e63d9..9822e04 100644
--- a/WebApi/Entities/AnswerEntity.cs
+++ b/WebApi/Entities/AnswerEntity.cs
@@ -3,24 +3,24 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
+ ///
+ /// define an entity for an answer for a Question with Mutiple Choice
+ /// properties :
+ /// Id : identifier in the database
+ /// Content : content of the answer
+ /// IdQuestion : the id of the question which it answer to
+ /// Question : the question which it answer to
+ ///
[Table("Answers")]
public class AnswerEntity
{
- ///
- /// define an entity for an answer for a Question with Mutiple Choice
- /// properties :
- /// Id : identifier in the database
- /// Content : content of the answer
- /// IdQuestion : the id of the question which it answer to
- /// Question : the question which it answer to
- ///
[Key]
- public uint? Id { get; set; }
+ public uint Id { get; set; }
public string Content { get; set; } = null!;
[ForeignKey(nameof(Question))]
- public uint IdQuestion { get; set; }
+ public uint? IdQuestion { get; set; }
- public QuestionEntity Question { get; set; } = null!;
+ public QuestionEntity? Question { get; set; }
}
}
diff --git a/WebApi/Entities/ChapterEntity.cs b/WebApi/Entities/ChapterEntity.cs
index 786e9c1..35f74cf 100644
--- a/WebApi/Entities/ChapterEntity.cs
+++ b/WebApi/Entities/ChapterEntity.cs
@@ -3,17 +3,17 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
+ ///
+ /// define a mathematical chapter or thematic
+ /// properties :
+ /// Id : identifier in the database
+ /// Name : name of the chapter
+ ///
[Table("Chapters")]
public class ChapterEntity
{
- ///
- /// define a mathematical chapter or thematic
- /// properties :
- /// Id : identifier in the database
- /// Name : name of the chapter
- ///
[Key]
- public uint? Id { get; set; }
+ public uint Id { get; set; }
public string Name { get; set; } = null!;
}
}
diff --git a/WebApi/Entities/LobbyEntity.cs b/WebApi/Entities/LobbyEntity.cs
index 65781d1..879eb0b 100644
--- a/WebApi/Entities/LobbyEntity.cs
+++ b/WebApi/Entities/LobbyEntity.cs
@@ -4,20 +4,20 @@ using System.Diagnostics.CodeAnalysis;
namespace Entities
{
+ ///
+ /// define a lobby for QMC rapidity fight
+ /// properties :
+ /// Id : identifier of the lobby in the database
+ /// Name : name of the lobby
+ /// Password : password require to access at the lobby
+ /// IdCreator : identifier of the creator player
+ /// Creator : the creator player
+ ///
[Table("Lobbies")]
public class LobbyEntity
{
- ///
- /// define a lobby for QMC rapidity fight
- /// properties :
- /// Id : identifier of the lobby in the database
- /// Name : name of the lobby
- /// Password : password require to access at the lobby
- /// IdCreator : identifier of the creator player
- /// Creator : the creator player
- ///
[Key]
- public uint? Id { get; set; }
+ public uint Id { get; set; }
public string Name { get; set; } = null!;
public string Password { get; set; } = null!;
public uint NbPlayers { get; set; }
diff --git a/WebApi/Entities/LobbyEntityPlayerEntity.cs b/WebApi/Entities/LobbyEntityPlayerEntity.cs
index c521d84..271d093 100644
--- a/WebApi/Entities/LobbyEntityPlayerEntity.cs
+++ b/WebApi/Entities/LobbyEntityPlayerEntity.cs
@@ -2,17 +2,17 @@
namespace Entities
{
+ ///
+ /// a class just to match with the model (this is the "utiliser" entity)
+ /// properties :
+ /// IdLobby : identifier of the lobby this is for
+ /// IdPlayer : identifier of the player this is for
+ /// Lobby : the lobby this is for
+ /// Player : the player this is for
+ ///
[Table("Use")]
public class LobbyEntityPlayerEntity
{
- ///
- /// a class just to match with the model (this is the "utiliser" entity)
- /// properties :
- /// IdLobby : identifier of the lobby this is for
- /// IdPlayer : identifier of the player this is for
- /// Lobby : the lobby this is for
- /// Player : the player this is for
- ///
[ForeignKey(nameof(Lobby))]
public uint IdLobby { get; set; }
diff --git a/WebApi/Entities/PlayerEntity.cs b/WebApi/Entities/PlayerEntity.cs
index 873c4e0..ed0f388 100644
--- a/WebApi/Entities/PlayerEntity.cs
+++ b/WebApi/Entities/PlayerEntity.cs
@@ -3,18 +3,18 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
+ ///
+ /// define an entity for a player
+ /// properties :
+ /// Id : identifier in the database
+ /// Nickname : nickname for the player
+ /// HashedPassword : hashed of the password of the player
+ ///
[Table("Players")]
public class PlayerEntity
{
- ///
- /// define an entity for a player
- /// properties :
- /// Id : identifier in the database
- /// Nickname : nickname for the player
- /// HashedPassword : hashed of the password of the player
- ///
[Key]
- public uint? Id { get; set; }
+ public uint Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}
diff --git a/WebApi/Entities/PlayerEntityChapterEntity.cs b/WebApi/Entities/PlayerEntityChapterEntity.cs
index 16d1c28..74f7a2a 100644
--- a/WebApi/Entities/PlayerEntityChapterEntity.cs
+++ b/WebApi/Entities/PlayerEntityChapterEntity.cs
@@ -8,17 +8,17 @@ using System.Threading.Tasks;
namespace Entities
{
+ ///
+ /// a class to storage the maximum score of a player for a chapter
+ /// properties :
+ /// IdChapter : identifier of the chapter this is for
+ /// IdPlayer : identifier of the player this is for
+ /// Chapter : the chapter this is for
+ /// Player : the player this is for
+ ///
[Table("Play")]
public class PlayerEntityChapterEntity
{
- ///
- /// a class to storage the maximum score of a player for a chapter
- /// properties :
- /// IdChapter : identifier of the chapter this is for
- /// IdPlayer : identifier of the player this is for
- /// Chapter : the chapter this is for
- /// Player : the player this is for
- ///
[ForeignKey(nameof(Chapter))]
public uint IdChapter { get; set; }
diff --git a/WebApi/Entities/QuestionEntity.cs b/WebApi/Entities/QuestionEntity.cs
index 523afde..0b2a573 100644
--- a/WebApi/Entities/QuestionEntity.cs
+++ b/WebApi/Entities/QuestionEntity.cs
@@ -8,23 +8,23 @@ using System.Threading.Tasks;
namespace Entities
{
+ ///
+ /// represent a mathematical question
+ /// properties :
+ /// Id : identifier of the question in the database
+ /// Content : the content of the question
+ /// Difficulty : difficulty (between 1 and 3 included) of the question
+ /// NbFails : number of time that people fail on this question
+ /// IdChapter : identifier of the chapter of the question
+ /// IdAnswerGood : identifier of the right answer to this question
+ /// Chapter : the chapter of the question
+ /// AnswerGood : the right answer to this question
+ ///
[Table("Questions")]
public class QuestionEntity
{
- ///
- /// represent a mathematical question
- /// properties :
- /// Id : identifier of the question in the database
- /// Content : the content of the question
- /// Difficulty : difficulty (between 1 and 3 included) of the question
- /// NbFails : number of time that people fail on this question
- /// IdChapter : identifier of the chapter of the question
- /// IdAnswerGood : identifier of the right answer to this question
- /// Chapter : the chapter of the question
- /// AnswerGood : the right answer to this question
- ///
[Key]
- public uint? Id { get; set; }
+ public uint Id { get; set; }
public string Content { get; set; } = null!;
[AllowedValues(1, 2, 3)]
public byte Difficulty { get; set; }
diff --git a/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs
new file mode 100644
index 0000000..89c592e
--- /dev/null
+++ b/WebApi/ExtensionsClassLibrairie/AdministratorExtensionMethods.cs
@@ -0,0 +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
+{
+ ///
+ /// define some methods to manipulate entity, model and dto adminstrators :
+ /// convert model to DTO, model to Entity, ...
+ /// and equality protocols
+ ///
+ public static class AdministratorExtensionMethods
+ {
+ // conversion methods
+ public static Administrator ToModel(this AdministratorEntity a)
+ => new Administrator(a.Username, a.HashedPassword, a.Id);
+ public static Administrator ToModel(this AdministratorDto a)
+ => new Administrator(a.Username, a.HashedPassword, a.Id);
+ public static AdministratorDto ToDto(this Administrator a)
+ => new AdministratorDto { Id = a.Id, HashedPassword = a.HashedPassword, Username = a.Username };
+ public static AdministratorEntity ToEntity(this Administrator a)
+ => new AdministratorEntity { Id = a.Id, HashedPassword = a.HashedPassword, Username = a.Username };
+
+ // reuse other methods
+ public static AdministratorDto ToDto(this AdministratorEntity a)
+ => a.ToModel().ToDto();
+ public static AdministratorEntity ToEntity(this AdministratorDto a)
+ => a.ToModel().ToEntity();
+
+ // equality protocols
+ public static bool Equals(this Administrator a1, Administrator a2)
+ => a1.Username == a2.Username;
+
+ // reuse other methods
+ public static bool Equals(this Administrator a1, AdministratorDto a2)
+ => a1.Equals(a2.ToModel());
+ public static bool Equals(this Administrator a1, AdministratorEntity a2)
+ => a1.Equals(a2.ToModel());
+ public static bool Equals(this AdministratorDto a1, Administrator a2)
+ => a1.ToModel().Equals(a2);
+ public static bool Equals(this AdministratorDto a1, AdministratorDto a2)
+ => a1.ToModel().Equals(a2.ToModel());
+ public static bool Equals(this AdministratorDto a1, AdministratorEntity a2)
+ => a1.ToModel().Equals(a2.ToModel());
+ public static bool Equals(this AdministratorEntity a1, Administrator a2)
+ => a1.ToModel().Equals(a2);
+ public static bool Equals(this AdministratorEntity a1, AdministratorDto a2)
+ => a1.ToModel().Equals(a2.ToModel());
+ public static bool Equals(this AdministratorEntity a1, AdministratorEntity a2)
+ => a1.ToModel().Equals(a2.ToModel());
+ }
+}
diff --git a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs
index 664d9cb..4d7dfd7 100644
--- a/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs
+++ b/WebApi/ExtensionsClassLibrairie/AnswerExtensionMethods.cs
@@ -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
{
+ ///
+ /// define some methods to manipulate entity, model and dto answers :
+ /// convert model to DTO, model to Entity, ...
+ /// and equality protocols
+ ///
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
+ // conversion methods
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
+ => 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 };
- ///
- /// convet an entity answer into a dto answer
- ///
- /// the entity answer to convert
- /// the dto answer that correspond
+ // reuse other methods
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;
- }
+ => 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());
}
}
diff --git a/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs
new file mode 100644
index 0000000..3652416
--- /dev/null
+++ b/WebApi/ExtensionsClassLibrairie/ChapterExtensionMethods.cs
@@ -0,0 +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
+{
+ ///
+ /// define some methods to manipulate entity, model and dto chapters :
+ /// convert model to DTO, model to Entity, ...
+ /// and equality protocols
+ ///
+ public static class ChapterExtensionMethods
+ {
+ // conversion methods
+ public static Chapter ToModel(this ChapterEntity c)
+ => new Chapter(c.Name, c.Id);
+ public static Chapter ToModel(this ChapterDto c)
+ => new Chapter(c.Name, c.Id);
+ public static ChapterDto ToDto(this Chapter c)
+ => new ChapterDto { Id = c.Id, Name = c.Name };
+ public static ChapterEntity ToEntity(this Chapter c)
+ => new ChapterEntity { Id = c.Id, Name = c.Name };
+
+ // reuse other methods
+ public static ChapterDto ToDto(this ChapterEntity c)
+ => c.ToModel().ToDto();
+ public static ChapterEntity ToEntity(this ChapterDto c)
+ => c.ToModel().ToEntity();
+
+ // equality protocols
+ public static bool Equals(this Chapter c1, Chapter c2)
+ => c1.Name == c2.Name;
+
+ // reuse other methods
+ public static bool Equals(this Chapter c1, ChapterDto c2)
+ => c1.Equals(c2.ToModel());
+ public static bool Equals(this Chapter c1, ChapterEntity c2)
+ => c1.Equals(c2.ToModel());
+ public static bool Equals(this ChapterDto c1, Chapter c2)
+ => c1.ToModel().Equals(c2);
+ public static bool Equals(this ChapterDto c1, ChapterDto c2)
+ => c1.ToModel().Equals(c2.ToModel());
+ public static bool Equals(this ChapterDto c1, ChapterEntity c2)
+ => c1.ToModel().Equals(c2.ToModel());
+ public static bool Equals(this ChapterEntity c1, Chapter c2)
+ => c1.ToModel().Equals(c2);
+ public static bool Equals(this ChapterEntity c1, ChapterDto c2)
+ => c1.ToModel().Equals(c2.ToModel());
+ public static bool Equals(this ChapterEntity c1, ChapterEntity c2)
+ => c1.ToModel().Equals(c2.ToModel());
+ }
+}
diff --git a/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs
new file mode 100644
index 0000000..ad34f8f
--- /dev/null
+++ b/WebApi/ExtensionsClassLibrairie/LobbyExtensionMethods.cs
@@ -0,0 +1,58 @@
+using DTOs;
+using Entities;
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ExtensionsClassLibrairie
+{///
+ /// define some methods to manipulate entity, model and dto lobbies :
+ /// convert model to DTO, model to Entity, ...
+ /// and equality protocols
+ ///
+ public static class LobbyExtensionMethods
+ {
+ // conversion methods
+ public static Lobby ToModel(this LobbyEntity l)
+ => new Lobby(l.Name, l.Creator.ToModel(), 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);
+ 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, NbPlayers = l.NbPlayers};
+ public static LobbyEntity ToEntity(this Lobby l)
+ => new LobbyEntity { Id = l.Id, Creator = l.Creator.ToEntity(), IdCreator = l.IdCreator,
+ Name = l.Name, Password = l.Password, NbPlayers = l.NbPlayers};
+
+ // reuse other methods
+ public static LobbyDto ToDto(this LobbyEntity l)
+ => l.ToModel().ToDto();
+ public static LobbyEntity ToEntity(this LobbyDto l)
+ => l.ToModel().ToEntity();
+
+ // equality protocols
+ public static bool Equals(this Lobby l1, Lobby l2)
+ => l1.Name == l2.Name && l1.IdCreator == l2.IdCreator;
+
+ // reuse other methods
+ public static bool Equals(this Lobby l1, LobbyDto l2)
+ => l1.Equals(l2.ToModel());
+ public static bool Equals(this Lobby l1, LobbyEntity l2)
+ => l1.Equals(l2.ToModel());
+ public static bool Equals(this LobbyDto l1, Lobby l2)
+ => l1.ToModel().Equals(l2);
+ public static bool Equals(this LobbyDto l1, LobbyDto l2)
+ => l1.ToModel().Equals(l2.ToModel());
+ public static bool Equals(this LobbyDto l1, LobbyEntity l2)
+ => l1.ToModel().Equals(l2.ToModel());
+ public static bool Equals(this LobbyEntity l1, Lobby l2)
+ => l1.ToModel().Equals(l2);
+ public static bool Equals(this LobbyEntity l1, LobbyDto l2)
+ => l1.ToModel().Equals(l2.ToModel());
+ public static bool Equals(this LobbyEntity l1, LobbyEntity l2)
+ => l1.ToModel().Equals(l2.ToModel());
+ }
+}
diff --git a/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs
new file mode 100644
index 0000000..ab9ffa3
--- /dev/null
+++ b/WebApi/ExtensionsClassLibrairie/PlayerExtensionMethods.cs
@@ -0,0 +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
+{
+ ///
+ /// define some methods to manipulate entity, model and dto players :
+ /// convert model to DTO, model to Entity, ...
+ /// and equality protocols
+ ///
+ public static class PlayerExtensionMethods
+ {
+ // conversion methods
+ public static Player ToModel(this PlayerEntity p)
+ => new Player(p.Nickname, p.HashedPassword, p.Id);
+ public static Player ToModel(this PlayerDto p)
+ => new Player(p.Nickname, p.HashedPassword, p.Id);
+ public static PlayerDto ToDto(this Player p)
+ => new PlayerDto { Id = p.Id, Nickname = p.Nickname, HashedPassword = p.HashedPassword};
+ public static PlayerEntity ToEntity(this Player p)
+ => new PlayerEntity { Id = p.Id, Nickname = p.Nickname, HashedPassword = p.HashedPassword };
+
+ // reuse other methods
+ public static PlayerDto ToDto(this PlayerEntity p)
+ => p.ToModel().ToDto();
+ public static PlayerEntity ToEntity(this PlayerDto p)
+ => p.ToModel().ToEntity();
+
+ // equality protocols
+ public static bool Equals(this Player p1, Player p2)
+ => p1.Nickname == p2.Nickname;
+
+ // reuse other methods
+ public static bool Equals(this Player p1, PlayerDto p2)
+ => p1.Equals(p2.ToModel());
+ public static bool Equals(this Player p1, PlayerEntity p2)
+ => p1.Equals(p2.ToModel());
+ public static bool Equals(this PlayerDto p1, Player p2)
+ => p1.ToModel().Equals(p2);
+ public static bool Equals(this PlayerDto p1, PlayerDto p2)
+ => p1.ToModel().Equals(p2.ToModel());
+ public static bool Equals(this PlayerDto p1, PlayerEntity p2)
+ => p1.ToModel().Equals(p2.ToModel());
+ public static bool Equals(this PlayerEntity p1, Player p2)
+ => p1.ToModel().Equals(p2);
+ public static bool Equals(this PlayerEntity p1, PlayerDto p2)
+ => p1.ToModel().Equals(p2.ToModel());
+ public static bool Equals(this PlayerEntity p1, PlayerEntity p2)
+ => p1.ToModel().Equals(p2.ToModel());
+ }
+}
diff --git a/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs b/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs
new file mode 100644
index 0000000..82d2659
--- /dev/null
+++ b/WebApi/ExtensionsClassLibrairie/QuestionExtensionMethods.cs
@@ -0,0 +1,69 @@
+using DTOs;
+using Entities;
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ExtensionsClassLibrairie
+{
+ ///
+ /// define some methods to manipulate entity, model and dto questions :
+ /// convert model to DTO, model to Entity, ...
+ /// and equality protocols
+ ///
+ public static class QuestionExtensionMethods
+ {
+ // conversion methods
+ public static Question ToModel(this QuestionEntity q)
+ {
+ var tmp = new Question(q.Content, q.Chapter?.ToModel(), q.Id, q.AnswerGood?.ToModel());
+ 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());
+ 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 };
+ 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 };
+
+ // reuse other methods
+ public static QuestionDto ToDto(this QuestionEntity q)
+ => q.ToModel().ToDto();
+ public static QuestionEntity ToEntity(this QuestionDto q)
+ => q.ToModel().ToEntity();
+
+ // equality protocols
+ public static bool Equals(this Question q1, Question q2)
+ => q1.Content == q2.Content;
+
+ // reuse other methods
+ public static bool Equals(this Question q1, QuestionDto q2)
+ => q1.Equals(q2.ToModel());
+ public static bool Equals(this Question q1, QuestionEntity q2)
+ => q1.Equals(q2.ToModel());
+ public static bool Equals(this QuestionDto q1, Question q2)
+ => q1.ToModel().Equals(q2);
+ public static bool Equals(this QuestionDto q1, QuestionDto q2)
+ => q1.ToModel().Equals(q2.ToModel());
+ public static bool Equals(this QuestionDto q1, QuestionEntity q2)
+ => q1.ToModel().Equals(q2.ToModel());
+ public static bool Equals(this QuestionEntity q1, Question q2)
+ => q1.ToModel().Equals(q2);
+ public static bool Equals(this QuestionEntity q1, QuestionDto q2)
+ => q1.ToModel().Equals(q2.ToModel());
+ public static bool Equals(this QuestionEntity q1, QuestionEntity q2)
+ => q1.ToModel().Equals(q2.ToModel());
+ }
+}
\ No newline at end of file
diff --git a/WebApi/Model/Administrator.cs b/WebApi/Model/Administrator.cs
index 23b722f..d7e80dd 100644
--- a/WebApi/Model/Administrator.cs
+++ b/WebApi/Model/Administrator.cs
@@ -7,25 +7,23 @@ using System.Threading.Tasks;
namespace Model
{
+ ///
+ /// define an administrator
+ /// attributes :
+ /// id : identifier in the database
+ /// username : username for a administrator
+ /// hashedPassword : hash of the password of the administrator
+ ///
public class Administrator
{
- ///
- /// define an administrator
- /// attributes :
- /// id : identifier in the database
- /// username : username for a administrator
- /// hashedPassword : hash of the password of the administrator
- ///
- private int id;
+ private uint id;
private string? username;
private string? hashedPassword;
- ///
- /// getters and setters for attributes
- ///
- public int Id
+ // getters and setters for attributes
+ public uint Id
{
get => id;
- private set { id = value < -1 ? -1 : value; }
+ private set { id = value; }
}
public string Username
{
@@ -44,7 +42,7 @@ namespace Model
/// the username of the administrator
/// the hash of the password of the administrator
/// the id in the database
- public Administrator(string username, string hashedPassword, int id = -1)
+ public Administrator(string username, string hashedPassword, uint id = 0)
{
this.Username = username;
this.HashedPassword = hashedPassword;
diff --git a/WebApi/Model/Answer.cs b/WebApi/Model/Answer.cs
index 24f87b6..6e10e70 100644
--- a/WebApi/Model/Answer.cs
+++ b/WebApi/Model/Answer.cs
@@ -3,44 +3,42 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Model
{
+ ///
+ /// define an answer for a Question with Mutiple Choice
+ /// attributes :
+ /// id : identifier in the database
+ /// content : content of the answer
+ /// idQuestion : the id of the question which it answer to
+ /// question : the question which it answer to
+ ///
public class Answer
{
- ///
- /// define an answer for a Question with Mutiple Choice
- /// attributes :
- /// id : identifier in the database
- /// content : content of the answer
- /// idQuestion : the id of the question which it answer to
- /// question : the question which it answer to
- ///
- private int id;
+ private uint id;
private string? content;
- private int idQuestion;
+ private uint idQuestion;
public Question? question;
- ///
- /// getters and setters for attributes
- ///
- public int? Id
+ // getters and setters for attributes
+ public uint Id
{
- get => id == -1 ? null : id; // null = no id
- private set { id = value < -1 || value == null ? -1 : value.Value; }
+ get => id;
+ private set { id = value; }
}
public string Content
{
get => content == null ? "" : content;
set { content = value == "" ? null : value; }
}
- public int? IdQuestion
+ public uint IdQuestion
{
- get => idQuestion == -1 ? null : idQuestion; // null = no idQuestion
- private set { idQuestion = value < -1 || value == null ? -1 : value.Value; }
+ get => idQuestion; // null = no idQuestion
+ private set { idQuestion = value; }
}
public Question? Question
{
get => question;
- private set { question = value; IdQuestion = value == null ? -1 : value.Id; }
+ private set { question = value; IdQuestion = value == null ? 0 : value.Id; }
}
///
/// constructor of an answer
@@ -48,7 +46,7 @@ namespace Model
/// the content of the answer
/// the id in the database
/// the question which it answer to
- public Answer(string content, Question? question = null, int? id = null)
+ public Answer(string content, Question? question = null, uint id = 0)
{
Content = content;
Id = id;
diff --git a/WebApi/Model/Chapter.cs b/WebApi/Model/Chapter.cs
index f3bf772..3c1662f 100644
--- a/WebApi/Model/Chapter.cs
+++ b/WebApi/Model/Chapter.cs
@@ -7,23 +7,21 @@ using System.Threading.Tasks;
namespace Model
{
+ ///
+ /// define a mathematical chapter or thematic
+ /// attributes :
+ /// id : identifier in the database
+ /// name : name of the chapter
+ ///
public class Chapter
{
- ///
- /// define a mathematical chapter or thematic
- /// attributes :
- /// id : identifier in the database
- /// name : name of the chapter
- ///
- int id;
+ uint id;
string? name;
- ///
- /// getters and setters for attributs
- ///
- public int? Id
+ // getters and setters for attributs
+ public uint Id
{
- get => id == -1 ? null : id ;
- private set { id = value == null || value < -1 ? -1 : value.Value; }
+ get => id;
+ private set { id = value; }
}
public string Name
{
@@ -36,7 +34,7 @@ namespace Model
///
/// name of the chapter
/// id in the database
- public Chapter(string name, int? id = null)
+ public Chapter(string name, uint id = 0)
{
Name = name;
Id = id;
diff --git a/WebApi/Model/Lobby.cs b/WebApi/Model/Lobby.cs
index f9dac85..c475cd6 100644
--- a/WebApi/Model/Lobby.cs
+++ b/WebApi/Model/Lobby.cs
@@ -8,30 +8,28 @@ using System.Threading.Tasks;
namespace Model
{
+ ///
+ /// define a lobby for QMC rapidity fight
+ /// attributes :
+ /// id : identifier of the lobby in the database
+ /// name : name of the lobby
+ /// password : password require to access at the lobby
+ /// idCreator : identifier of the creator player
+ /// creator : the creator player
+ ///
public class Lobby
{
- ///
- /// define a lobby for QMC rapidity fight
- /// attributes :
- /// id : identifier of the lobby in the database
- /// name : name of the lobby
- /// password : password require to access at the lobby
- /// idCreator : identifier of the creator player
- /// creator : the creator player
- ///
- private int id;
+ private uint id;
private string? name;
private string? password;
- private int nbPlayers;
- private int idCreator;
+ private uint nbPlayers;
+ private uint? idCreator;
private Player creator;
- ///
- /// getters and setters of attributes
- ///
- public int? Id
+ // getters and setters of attributes
+ public uint Id
{
- get => id == -1 ? null : id;
- private set { id = value == null || value < -1 ? -1 : value.Value; }
+ get => id;
+ private set { id = value; }
}
public string Name
{
@@ -43,15 +41,15 @@ namespace Model
get => password == null ? "" : password;
private set { password = value == "" ? null : value; }
}
- public int NbPlayers
+ public uint NbPlayers
{
get => nbPlayers;
- set { nbPlayers = value < 0 ? 0 : value; }
+ set { nbPlayers = value; }
}
- public int? IdCreator
+ public uint? IdCreator
{
- get => idCreator == -1 ? null : id;
- private set { idCreator = value == null || value < -1 ? -1 : value.Value; }
+ get => idCreator;
+ private set { idCreator = value; }
}
public Player Creator
{
@@ -67,12 +65,12 @@ namespace Model
/// the password require to access to the lobby
/// the number of players in the lobby
/// the id of the lobby
- public Lobby(string name, Player creator, string password = "", int nbPlayer = 0, int? id = null)
+ public Lobby(string name, Player creator, string password = "", uint nbPlayers = 0, uint id = 0)
{
Name = name;
Creator = creator;
Password = password;
- NbPlayers = nbPlayer;
+ NbPlayers = nbPlayers;
Id = id;
}
}
diff --git a/WebApi/Model/Player.cs b/WebApi/Model/Player.cs
index ee70ae7..92382f5 100644
--- a/WebApi/Model/Player.cs
+++ b/WebApi/Model/Player.cs
@@ -7,23 +7,21 @@ using System.Threading.Tasks;
namespace Model
{
+ ///
+ /// define a player
+ /// attributes :
+ /// id : identifier in the database
+ /// nickname : nickname for the player
+ /// hashedPassword : hashed of the password of the player
+ ///
public class Player
{
- ///
- /// define a player
- /// attributes :
- /// id : identifier in the database
- /// nickname : nickname for the player
- /// hashedPassword : hashed of the password of the player
- ///
- private int id;
+ private uint id;
private string? nickname;
private string? hashedPassword;
- ///
- /// getters and setters for attributes
- ///
- public int Id
+ // getters and setters for attributes
+ public uint Id
{
get => id;
private set { id = value; }
@@ -45,7 +43,7 @@ namespace Model
/// nickname of the player
/// hash of the password of the player
/// id of the player
- public Player(string nickname, string hashedPassword = "", int? id = null)
+ public Player(string nickname, string hashedPassword = "", uint id = 0)
{
Nickname = nickname;
HashedPassword = hashedPassword;
diff --git a/WebApi/Model/Question.cs b/WebApi/Model/Question.cs
index ead4d2f..cec0bec 100644
--- a/WebApi/Model/Question.cs
+++ b/WebApi/Model/Question.cs
@@ -8,73 +8,73 @@ using System.Threading.Tasks;
namespace Model
{
+ ///
+ /// represent a mathematical question
+ /// attributes :
+ /// id : identifier of the question in the database
+ /// content : the content of the question
+ /// difficulty : difficulty (between 1 and 3 included) of the question
+ /// nbFails : number of time that people fail on this question
+ /// idChapter : identifier of the chapter of the question
+ /// idAnswerGood : identifier of the right answer to this question
+ /// chapter : the chapter of the question
+ /// answerGood : the right answer to this question
+ ///
public class Question
{
- ///
- /// represent a mathematical question
- /// attributes :
- /// id : identifier of the question in the database
- /// content : the content of the question
- /// difficulty : difficulty (between 1 and 3 included) of the question
- /// nbFails : number of time that people fail on this question
- /// idChapter : identifier of the chapter of the question
- /// idAnswerGood : identifier of the right answer to this question
- /// chapter : the chapter of the question
- /// answerGood : the right answer to this question
- ///
- private int id;
+ private uint id;
private string? content;
- private int difficulty;
- private int nbFalls;
- private int idChapter;
- private int idAnswerGood;
+ private byte difficulty;
+ private uint nbFalls;
+ private uint idChapter;
+ private uint idAnswerGood;
private Chapter? chapter;
private Answer? answerGood;
- public int? Id
+ public uint Id
{
- get => id == -1 ? null : id;
- private set { id = value == null || value < -1 ? -1 : value.Value; }
+ get => id;
+ private set { id = value; }
}
public string Content
{
get => content == null ? "" : content;
set { content = value == "" ? null : value;}
}
- public int Difficulty
+ public byte Difficulty
{
get => difficulty;
- set { difficulty = value < 0 ? 0 : value; }
+ set { difficulty = value; }
}
- public int NbFalls
+ public uint NbFalls
{
get => nbFalls;
- set { nbFalls = value < 0 ? 0 : value; }
+ set { nbFalls = value; }
}
- public int? IdChapter
+ public uint IdChapter
{
- get => idChapter == -1 ? null : idChapter;
- private set { idChapter = value == null || value < -1 ? -1 : value.Value; }
+ get => idChapter;
+ private set { idChapter = value; }
}
- public int? IdAnswerGood
+ public uint IdAnswerGood
{
- get => idAnswerGood == -1 ? null : idAnswerGood;
- set { idAnswerGood = value == null || value < -1 ? -1 : value.Value; }
+ get => idAnswerGood;
+ set { idAnswerGood = value; }
}
public Chapter? Chapter
{
get => chapter;
- set { chapter = value; IdChapter = value == null ? -1 : value.Id; }
+ set { chapter = value; IdChapter = value == null ? 0 : value.Id; }
}
public Answer? AnswerGood
{
get => answerGood;
- set { answerGood = value; IdAnswerGood = value == null ? -1 : value.Id; }
+ set { answerGood = value; IdAnswerGood = value == null ? 0 : value.Id; }
}
- public Question(string content, Chapter? chapter = null, int id = -1, Answer? answerGood = null)
+ public Question(string content, Chapter? chapter = null, uint id = 0, Answer? answerGood = null)
{
Id = id;
Content = content;