feat : création des classes d'extensions
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent f972a3a9c9
commit aac8bf623b

@ -7,8 +7,6 @@ using System.Threading.Tasks;
namespace DTOs namespace DTOs
{ {
public class AdministratorDto
{
/// <summary> /// <summary>
/// define a DTO for an administrator /// define a DTO for an administrator
/// properties : /// properties :
@ -16,7 +14,9 @@ namespace DTOs
/// Username : username for a administrator /// Username : username for a administrator
/// HashedPassword : hash of the password of the administrator /// HashedPassword : hash of the password of the administrator
/// </summary> /// </summary>
public int? Id { get; set; } public class AdministratorDto
{
public uint Id { get; set; }
public string Username { get; set; } = null!; public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!; public string HashedPassword { get; set; } = null!;
} }

@ -3,8 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DTOs namespace DTOs
{ {
public class AnswerDto
{
/// <summary> /// <summary>
/// define a DTO for an answer for a Question with Mutiple Choice /// define a DTO for an answer for a Question with Mutiple Choice
/// properties : /// properties :
@ -13,10 +11,12 @@ namespace DTOs
/// IdQuestion : the id of the question which it answer to /// IdQuestion : the id of the question which it answer to
/// Question : the question which it answer to /// Question : the question which it answer to
/// </summary> /// </summary>
public int? Id { get; set; } public class AnswerDto
{
public uint Id { get; set; }
public string Content { get; set; } = null!; 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!;
} }
} }

@ -7,15 +7,15 @@ using System.Threading.Tasks;
namespace DTOs namespace DTOs
{ {
public class ChapterDto
{
/// <summary> /// <summary>
/// define a mathematical chapter or thematic /// define a mathematical chapter or thematic
/// properties : /// properties :
/// Id : identifier in the database /// Id : identifier in the database
/// Name : name of the chapter /// Name : name of the chapter
/// </summary> /// </summary>
public int? Id { get; set; } public class ChapterDto
{
public uint Id { get; set; }
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
} }
} }

@ -8,8 +8,6 @@ using System.Threading.Tasks;
namespace DTOs namespace DTOs
{ {
public class LobbyDto
{
/// <summary> /// <summary>
/// define a lobby for QMC rapidity fight /// define a lobby for QMC rapidity fight
/// properties : /// properties :
@ -19,11 +17,13 @@ namespace DTOs
/// IdCreator : identifier of the creator player /// IdCreator : identifier of the creator player
/// Creator : the creator player /// Creator : the creator player
/// </summary> /// </summary>
public int? Id { get; set; } public class LobbyDto
{
public uint Id { get; set; }
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
public string Password { get; set; } = null!; public string Password { get; set; } = null!;
public int NbPlayers { get; set; } public uint NbPlayers { get; set; }
public int? IdCreator { get; set; } public uint? IdCreator { get; set; }
public PlayerDto Creator { get; set; } = null!; public PlayerDto Creator { get; set; } = null!;
} }
} }

@ -7,8 +7,6 @@ using System.Threading.Tasks;
namespace DTOs namespace DTOs
{ {
public class PlayerDto
{
/// <summary> /// <summary>
/// define a DTO for a player /// define a DTO for a player
/// properties : /// properties :
@ -16,7 +14,9 @@ namespace DTOs
/// Nickname : nickname for the player /// Nickname : nickname for the player
/// HashedPassword : hashed of the password of the player /// HashedPassword : hashed of the password of the player
/// </summary> /// </summary>
public int? Id { get; set; } public class PlayerDto
{
public uint Id { get; set; }
public string Nickname { get; set; } = null!; public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!; public string HashedPassword { get; set; } = null!;
} }

@ -8,8 +8,6 @@ using System.Threading.Tasks;
namespace DTOs namespace DTOs
{ {
public class QuestionDto
{
/// <summary> /// <summary>
/// represent a mathematical question /// represent a mathematical question
/// properties : /// properties :
@ -22,12 +20,14 @@ namespace DTOs
/// Chapter : the chapter of the question /// Chapter : the chapter of the question
/// AnswerGood : the right answer to this question /// AnswerGood : the right answer to this question
/// </summary> /// </summary>
public int? Id { get; set; } public class QuestionDto
{
public uint Id { get; set; }
public string Content { get; set; } = null!; public string Content { get; set; } = null!;
public int Difficulty { get; set; } public byte Difficulty { get; set; }
public int NbFalls { get; set; } public uint NbFalls { get; set; }
public int? IdChapter { get; set; } public uint? IdChapter { get; set; }
public int? IdAnswerGood { get; set; } public uint? IdAnswerGood { get; set; }
public ChapterDto? Chapter { get; set; } public ChapterDto? Chapter { get; set; }
public AnswerDto? AnswerGood { get; set; } public AnswerDto? AnswerGood { get; set; }
} }

@ -3,9 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities namespace Entities
{ {
[Table("Administrators")]
public class AdministratorEntity
{
/// <summary> /// <summary>
/// define an entity for an administrator /// define an entity for an administrator
/// properties : /// properties :
@ -13,8 +10,11 @@ namespace Entities
/// Username : username for a administrator /// Username : username for a administrator
/// HashedPassword : hash of the password of the administrator /// HashedPassword : hash of the password of the administrator
/// </summary> /// </summary>
[Table("Administrators")]
public class AdministratorEntity
{
[Key] [Key]
public uint? Id { get; set; } public uint Id { get; set; }
public string Username { get; set; } = null!; public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!; public string HashedPassword { get; set; } = null!;
} }

@ -3,9 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities namespace Entities
{ {
[Table("Answers")]
public class AnswerEntity
{
/// <summary> /// <summary>
/// define an entity for an answer for a Question with Mutiple Choice /// define an entity for an answer for a Question with Mutiple Choice
/// properties : /// properties :
@ -14,13 +11,16 @@ namespace Entities
/// IdQuestion : the id of the question which it answer to /// IdQuestion : the id of the question which it answer to
/// Question : the question which it answer to /// Question : the question which it answer to
/// </summary> /// </summary>
[Table("Answers")]
public class AnswerEntity
{
[Key] [Key]
public uint? Id { get; set; } public uint Id { get; set; }
public string Content { get; set; } = null!; public string Content { get; set; } = null!;
[ForeignKey(nameof(Question))] [ForeignKey(nameof(Question))]
public uint IdQuestion { get; set; } public uint? IdQuestion { get; set; }
public QuestionEntity Question { get; set; } = null!; public QuestionEntity? Question { get; set; }
} }
} }

@ -3,17 +3,17 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities namespace Entities
{ {
[Table("Chapters")]
public class ChapterEntity
{
/// <summary> /// <summary>
/// define a mathematical chapter or thematic /// define a mathematical chapter or thematic
/// properties : /// properties :
/// Id : identifier in the database /// Id : identifier in the database
/// Name : name of the chapter /// Name : name of the chapter
/// </summary> /// </summary>
[Table("Chapters")]
public class ChapterEntity
{
[Key] [Key]
public uint? Id { get; set; } public uint Id { get; set; }
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
} }
} }

@ -4,9 +4,6 @@ using System.Diagnostics.CodeAnalysis;
namespace Entities namespace Entities
{ {
[Table("Lobbies")]
public class LobbyEntity
{
/// <summary> /// <summary>
/// define a lobby for QMC rapidity fight /// define a lobby for QMC rapidity fight
/// properties : /// properties :
@ -16,8 +13,11 @@ namespace Entities
/// IdCreator : identifier of the creator player /// IdCreator : identifier of the creator player
/// Creator : the creator player /// Creator : the creator player
/// </summary> /// </summary>
[Table("Lobbies")]
public class LobbyEntity
{
[Key] [Key]
public uint? Id { get; set; } public uint Id { get; set; }
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
public string Password { get; set; } = null!; public string Password { get; set; } = null!;
public uint NbPlayers { get; set; } public uint NbPlayers { get; set; }

@ -2,9 +2,6 @@
namespace Entities namespace Entities
{ {
[Table("Use")]
public class LobbyEntityPlayerEntity
{
/// <summary> /// <summary>
/// a class just to match with the model (this is the "utiliser" entity) /// a class just to match with the model (this is the "utiliser" entity)
/// properties : /// properties :
@ -13,6 +10,9 @@ namespace Entities
/// Lobby : the lobby this is for /// Lobby : the lobby this is for
/// Player : the player this is for /// Player : the player this is for
/// </summary> /// </summary>
[Table("Use")]
public class LobbyEntityPlayerEntity
{
[ForeignKey(nameof(Lobby))] [ForeignKey(nameof(Lobby))]
public uint IdLobby { get; set; } public uint IdLobby { get; set; }

@ -3,9 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities namespace Entities
{ {
[Table("Players")]
public class PlayerEntity
{
/// <summary> /// <summary>
/// define an entity for a player /// define an entity for a player
/// properties : /// properties :
@ -13,8 +10,11 @@ namespace Entities
/// Nickname : nickname for the player /// Nickname : nickname for the player
/// HashedPassword : hashed of the password of the player /// HashedPassword : hashed of the password of the player
/// </summary> /// </summary>
[Table("Players")]
public class PlayerEntity
{
[Key] [Key]
public uint? Id { get; set; } public uint Id { get; set; }
public string Nickname { get; set; } = null!; public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!; public string HashedPassword { get; set; } = null!;
} }

@ -8,9 +8,6 @@ using System.Threading.Tasks;
namespace Entities namespace Entities
{ {
[Table("Play")]
public class PlayerEntityChapterEntity
{
/// <summary> /// <summary>
/// a class to storage the maximum score of a player for a chapter /// a class to storage the maximum score of a player for a chapter
/// properties : /// properties :
@ -19,6 +16,9 @@ namespace Entities
/// Chapter : the chapter this is for /// Chapter : the chapter this is for
/// Player : the player this is for /// Player : the player this is for
/// </summary> /// </summary>
[Table("Play")]
public class PlayerEntityChapterEntity
{
[ForeignKey(nameof(Chapter))] [ForeignKey(nameof(Chapter))]
public uint IdChapter { get; set; } public uint IdChapter { get; set; }

@ -8,9 +8,6 @@ using System.Threading.Tasks;
namespace Entities namespace Entities
{ {
[Table("Questions")]
public class QuestionEntity
{
/// <summary> /// <summary>
/// represent a mathematical question /// represent a mathematical question
/// properties : /// properties :
@ -23,8 +20,11 @@ namespace Entities
/// Chapter : the chapter of the question /// Chapter : the chapter of the question
/// AnswerGood : the right answer to this question /// AnswerGood : the right answer to this question
/// </summary> /// </summary>
[Table("Questions")]
public class QuestionEntity
{
[Key] [Key]
public uint? Id { get; set; } public uint Id { get; set; }
public string Content { get; set; } = null!; public string Content { get; set; } = null!;
[AllowedValues(1, 2, 3)] [AllowedValues(1, 2, 3)]
public byte Difficulty { get; set; } public byte Difficulty { get; set; }

@ -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
{
/// <summary>
/// define some methods to manipulate entity, model and dto adminstrators :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
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());
}
}

@ -1,102 +1,57 @@
using DTOs; using DTOs;
using Entities; using Entities;
using Model; using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExtensionsClassLibrairie namespace ExtensionsClassLibrairie
{ {
public static class AnswerExtensionMethods
{
/// <summary> /// <summary>
/// convet a dto answer into a model answer /// define some methods to manipulate entity, model and dto answers :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary> /// </summary>
/// <param name="a">the dto answer to convert</param> public static class AnswerExtensionMethods
/// <returns>the model answer that correspond</returns>
public static Answer ToModel(this AnswerDto a)
{ {
return new Answer(a.Content, a.Id); // conversion methods
}
/// <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>
public static Answer ToModel(this AnswerEntity a) public static Answer ToModel(this AnswerEntity a)
{ => new Answer(a.Content, a.Question?.ToModel(), a.Id);
return new Answer(a.Content, a.Id); public static Answer ToModel(this AnswerDto a)
} => new Answer(a.Content, a.Question?.ToModel(), 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>
public static AnswerDto ToDto(this Answer a) public static AnswerDto ToDto(this Answer a)
{ => new AnswerDto { Id = a.Id, Content = a.Content, Question = a.Question?.ToDto(), IdQuestion = a.IdQuestion };
return new AnswerDto public static AnswerEntity ToEntity(this Answer a)
{ => new AnswerEntity { Id = a.Id, Content = a.Content, Question = a.Question?.ToEntity(), IdQuestion = a.IdQuestion };
Content = a.Content,
Id = a.Id
};
}
/// <summary> // reuse other methods
/// 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>
public static AnswerDto ToDto(this AnswerEntity a) public static AnswerDto ToDto(this AnswerEntity a)
{ => a.ToModel().ToDto();
return new AnswerDto public static AnswerEntity ToEntity(this AnswerDto a)
{ => a.ToModel().ToEntity();
Content = a.Content,
Id = a.Id // equality protocols
}; public static bool Equals(this Answer a1, Answer a2)
} => a1.Content == a2.Content && a1.IdQuestion == a2.IdQuestion;
/// <summary> // reuse other methods
/// equality protocole public static bool Equals(this Answer a1, AnswerDto a2)
/// </summary> => a1.Equals(a2.ToModel());
/// <param name="obj">an object</param> public static bool Equals(this Answer a1, AnswerEntity a2)
/// <returns> => a1.Equals(a2.ToModel());
/// true if the object is an AnswerEntity public static bool Equals(this AnswerDto a1, Answer a2)
/// and the two contents are equals => a1.ToModel().Equals(a2);
/// (we don't care about the id because public static bool Equals(this AnswerDto a1, AnswerDto a2)
/// he's set by the database => a1.ToModel().Equals(a2.ToModel());
/// </returns> public static bool Equals(this AnswerDto a1, AnswerEntity a2)
public static bool Equals(this AnswerEntity a, object? obj) => a1.ToModel().Equals(a2.ToModel());
{ public static bool Equals(this AnswerEntity a1, Answer a2)
return obj != null && obj is AnswerEntity other => a1.ToModel().Equals(a2);
&& other.Content == a.Content; 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());
} }
} }

@ -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
{
/// <summary>
/// define some methods to manipulate entity, model and dto chapters :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
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());
}
}

@ -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
{/// <summary>
/// define some methods to manipulate entity, model and dto lobbies :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
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());
}
}

@ -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
{
/// <summary>
/// define some methods to manipulate entity, model and dto players :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
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());
}
}

@ -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
{
/// <summary>
/// define some methods to manipulate entity, model and dto questions :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
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());
}
}

@ -7,8 +7,6 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Administrator
{
/// <summary> /// <summary>
/// define an administrator /// define an administrator
/// attributes : /// attributes :
@ -16,16 +14,16 @@ namespace Model
/// username : username for a administrator /// username : username for a administrator
/// hashedPassword : hash of the password of the administrator /// hashedPassword : hash of the password of the administrator
/// </summary> /// </summary>
private int id; public class Administrator
{
private uint id;
private string? username; private string? username;
private string? hashedPassword; private string? hashedPassword;
/// <summary> // getters and setters for attributes
/// getters and setters for attributes public uint Id
/// </summary>
public int Id
{ {
get => id; get => id;
private set { id = value < -1 ? -1 : value; } private set { id = value; }
} }
public string Username public string Username
{ {
@ -44,7 +42,7 @@ namespace Model
/// <param name="username">the username of the administrator</param> /// <param name="username">the username of the administrator</param>
/// <param name="hashedPassword">the hash of the password of the administrator</param> /// <param name="hashedPassword">the hash of the password of the administrator</param>
/// <param name="id">the id in the database</param> /// <param name="id">the id in the database</param>
public Administrator(string username, string hashedPassword, int id = -1) public Administrator(string username, string hashedPassword, uint id = 0)
{ {
this.Username = username; this.Username = username;
this.HashedPassword = hashedPassword; this.HashedPassword = hashedPassword;

@ -3,8 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Model namespace Model
{ {
public class Answer
{
/// <summary> /// <summary>
/// define an answer for a Question with Mutiple Choice /// define an answer for a Question with Mutiple Choice
/// attributes : /// attributes :
@ -13,34 +11,34 @@ namespace Model
/// idQuestion : the id of the question which it answer to /// idQuestion : the id of the question which it answer to
/// question : the question which it answer to /// question : the question which it answer to
/// </summary> /// </summary>
private int id; public class Answer
{
private uint id;
private string? content; private string? content;
private int idQuestion; private uint idQuestion;
public Question? question; public Question? question;
/// <summary> // getters and setters for attributes
/// getters and setters for attributes public uint Id
/// </summary>
public int? Id
{ {
get => id == -1 ? null : id; // null = no id get => id;
private set { id = value < -1 || value == null ? -1 : value.Value; } private set { id = value; }
} }
public string Content public string Content
{ {
get => content == null ? "" : content; get => content == null ? "" : content;
set { content = value == "" ? null : value; } set { content = value == "" ? null : value; }
} }
public int? IdQuestion public uint IdQuestion
{ {
get => idQuestion == -1 ? null : idQuestion; // null = no idQuestion get => idQuestion; // null = no idQuestion
private set { idQuestion = value < -1 || value == null ? -1 : value.Value; } private set { idQuestion = value; }
} }
public Question? Question public Question? Question
{ {
get => question; get => question;
private set { question = value; IdQuestion = value == null ? -1 : value.Id; } private set { question = value; IdQuestion = value == null ? 0 : value.Id; }
} }
/// <summary> /// <summary>
/// constructor of an answer /// constructor of an answer
@ -48,7 +46,7 @@ namespace Model
/// <param name="content">the content of the answer</param> /// <param name="content">the content of the answer</param>
/// <param name="id">the id in the database</param> /// <param name="id">the id in the database</param>
/// <param name="question">the question which it answer to</param> /// <param name="question">the question which it answer to</param>
public Answer(string content, Question? question = null, int? id = null) public Answer(string content, Question? question = null, uint id = 0)
{ {
Content = content; Content = content;
Id = id; Id = id;

@ -7,23 +7,21 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Chapter
{
/// <summary> /// <summary>
/// define a mathematical chapter or thematic /// define a mathematical chapter or thematic
/// attributes : /// attributes :
/// id : identifier in the database /// id : identifier in the database
/// name : name of the chapter /// name : name of the chapter
/// </summary> /// </summary>
int id; public class Chapter
{
uint id;
string? name; string? name;
/// <summary> // getters and setters for attributs
/// getters and setters for attributs public uint Id
/// </summary>
public int? Id
{ {
get => id == -1 ? null : id ; get => id;
private set { id = value == null || value < -1 ? -1 : value.Value; } private set { id = value; }
} }
public string Name public string Name
{ {
@ -36,7 +34,7 @@ namespace Model
/// </summary> /// </summary>
/// <param name="name">name of the chapter</param> /// <param name="name">name of the chapter</param>
/// <param name="id">id in the database</param> /// <param name="id">id in the database</param>
public Chapter(string name, int? id = null) public Chapter(string name, uint id = 0)
{ {
Name = name; Name = name;
Id = id; Id = id;

@ -8,8 +8,6 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Lobby
{
/// <summary> /// <summary>
/// define a lobby for QMC rapidity fight /// define a lobby for QMC rapidity fight
/// attributes : /// attributes :
@ -19,19 +17,19 @@ namespace Model
/// idCreator : identifier of the creator player /// idCreator : identifier of the creator player
/// creator : the creator player /// creator : the creator player
/// </summary> /// </summary>
private int id; public class Lobby
{
private uint id;
private string? name; private string? name;
private string? password; private string? password;
private int nbPlayers; private uint nbPlayers;
private int idCreator; private uint? idCreator;
private Player creator; private Player creator;
/// <summary> // getters and setters of attributes
/// getters and setters of attributes public uint Id
/// </summary>
public int? Id
{ {
get => id == -1 ? null : id; get => id;
private set { id = value == null || value < -1 ? -1 : value.Value; } private set { id = value; }
} }
public string Name public string Name
{ {
@ -43,15 +41,15 @@ namespace Model
get => password == null ? "" : password; get => password == null ? "" : password;
private set { password = value == "" ? null : value; } private set { password = value == "" ? null : value; }
} }
public int NbPlayers public uint NbPlayers
{ {
get => nbPlayers; get => nbPlayers;
set { nbPlayers = value < 0 ? 0 : value; } set { nbPlayers = value; }
} }
public int? IdCreator public uint? IdCreator
{ {
get => idCreator == -1 ? null : id; get => idCreator;
private set { idCreator = value == null || value < -1 ? -1 : value.Value; } private set { idCreator = value; }
} }
public Player Creator public Player Creator
{ {
@ -67,12 +65,12 @@ namespace Model
/// <param name="password">the password require to access to the lobby</param> /// <param name="password">the password require to access to the lobby</param>
/// <param name="nbPlayer">the number of players in the lobby</param> /// <param name="nbPlayer">the number of players in the lobby</param>
/// <param name="id">the id of the lobby</param> /// <param name="id">the id of the lobby</param>
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; Name = name;
Creator = creator; Creator = creator;
Password = password; Password = password;
NbPlayers = nbPlayer; NbPlayers = nbPlayers;
Id = id; Id = id;
} }
} }

@ -7,8 +7,6 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Player
{
/// <summary> /// <summary>
/// define a player /// define a player
/// attributes : /// attributes :
@ -16,14 +14,14 @@ namespace Model
/// nickname : nickname for the player /// nickname : nickname for the player
/// hashedPassword : hashed of the password of the player /// hashedPassword : hashed of the password of the player
/// </summary> /// </summary>
private int id; public class Player
{
private uint id;
private string? nickname; private string? nickname;
private string? hashedPassword; private string? hashedPassword;
/// <summary> // getters and setters for attributes
/// getters and setters for attributes public uint Id
/// </summary>
public int Id
{ {
get => id; get => id;
private set { id = value; } private set { id = value; }
@ -45,7 +43,7 @@ namespace Model
/// <param name="nickname">nickname of the player</param> /// <param name="nickname">nickname of the player</param>
/// <param name="hashedPassword">hash of the password of the player</param> /// <param name="hashedPassword">hash of the password of the player</param>
/// <param name="id">id of the player</param> /// <param name="id">id of the player</param>
public Player(string nickname, string hashedPassword = "", int? id = null) public Player(string nickname, string hashedPassword = "", uint id = 0)
{ {
Nickname = nickname; Nickname = nickname;
HashedPassword = hashedPassword; HashedPassword = hashedPassword;

@ -8,8 +8,6 @@ using System.Threading.Tasks;
namespace Model namespace Model
{ {
public class Question
{
/// <summary> /// <summary>
/// represent a mathematical question /// represent a mathematical question
/// attributes : /// attributes :
@ -22,59 +20,61 @@ namespace Model
/// chapter : the chapter of the question /// chapter : the chapter of the question
/// answerGood : the right answer to this question /// answerGood : the right answer to this question
/// </summary> /// </summary>
private int id; public class Question
{
private uint id;
private string? content; private string? content;
private int difficulty; private byte difficulty;
private int nbFalls; private uint nbFalls;
private int idChapter; private uint idChapter;
private int idAnswerGood; private uint idAnswerGood;
private Chapter? chapter; private Chapter? chapter;
private Answer? answerGood; private Answer? answerGood;
public int? Id public uint Id
{ {
get => id == -1 ? null : id; get => id;
private set { id = value == null || value < -1 ? -1 : value.Value; } private set { id = value; }
} }
public string Content public string Content
{ {
get => content == null ? "" : content; get => content == null ? "" : content;
set { content = value == "" ? null : value;} set { content = value == "" ? null : value;}
} }
public int Difficulty public byte Difficulty
{ {
get => difficulty; get => difficulty;
set { difficulty = value < 0 ? 0 : value; } set { difficulty = value; }
} }
public int NbFalls public uint NbFalls
{ {
get => nbFalls; get => nbFalls;
set { nbFalls = value < 0 ? 0 : value; } set { nbFalls = value; }
} }
public int? IdChapter public uint IdChapter
{ {
get => idChapter == -1 ? null : idChapter; get => idChapter;
private set { idChapter = value == null || value < -1 ? -1 : value.Value; } private set { idChapter = value; }
} }
public int? IdAnswerGood public uint IdAnswerGood
{ {
get => idAnswerGood == -1 ? null : idAnswerGood; get => idAnswerGood;
set { idAnswerGood = value == null || value < -1 ? -1 : value.Value; } set { idAnswerGood = value; }
} }
public Chapter? Chapter public Chapter? Chapter
{ {
get => chapter; get => chapter;
set { chapter = value; IdChapter = value == null ? -1 : value.Id; } set { chapter = value; IdChapter = value == null ? 0 : value.Id; }
} }
public Answer? AnswerGood public Answer? AnswerGood
{ {
get => 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; Id = id;
Content = content; Content = content;

Loading…
Cancel
Save