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,16 +7,16 @@ using System.Threading.Tasks;
namespace DTOs
{
/// <summary>
/// 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
/// </summary>
public class AdministratorDto
{
/// <summary>
/// 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
/// </summary>
public int? Id { get; set; }
public uint Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -3,20 +3,20 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace DTOs
{
/// <summary>
/// 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
/// </summary>
public class AnswerDto
{
/// <summary>
/// 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
/// </summary>
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!;
}
}

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

@ -8,22 +8,22 @@ using System.Threading.Tasks;
namespace DTOs
{
/// <summary>
/// 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
/// </summary>
public class LobbyDto
{
/// <summary>
/// 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
/// </summary>
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!;
}
}

@ -7,16 +7,16 @@ using System.Threading.Tasks;
namespace DTOs
{
/// <summary>
/// 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
/// </summary>
public class PlayerDto
{
/// <summary>
/// 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
/// </summary>
public int? Id { get; set; }
public uint Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -8,26 +8,26 @@ using System.Threading.Tasks;
namespace DTOs
{
/// <summary>
/// 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
/// </summary>
public class QuestionDto
{
/// <summary>
/// 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
/// </summary>
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; }
}

@ -3,18 +3,18 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Administrators")]
public class AdministratorEntity
{
/// <summary>
/// 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
/// </summary>
[Key]
public uint? Id { get; set; }
public uint Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -3,24 +3,24 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Answers")]
public class AnswerEntity
{
/// <summary>
/// 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
/// </summary>
[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; }
}
}

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

@ -4,20 +4,20 @@ using System.Diagnostics.CodeAnalysis;
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Lobbies")]
public class LobbyEntity
{
/// <summary>
/// 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
/// </summary>
[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; }

@ -2,17 +2,17 @@
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Use")]
public class LobbyEntityPlayerEntity
{
/// <summary>
/// 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
/// </summary>
[ForeignKey(nameof(Lobby))]
public uint IdLobby { get; set; }

@ -3,18 +3,18 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Players")]
public class PlayerEntity
{
/// <summary>
/// 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
/// </summary>
[Key]
public uint? Id { get; set; }
public uint Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -8,17 +8,17 @@ using System.Threading.Tasks;
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Play")]
public class PlayerEntityChapterEntity
{
/// <summary>
/// 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
/// </summary>
[ForeignKey(nameof(Chapter))]
public uint IdChapter { get; set; }

@ -8,23 +8,23 @@ using System.Threading.Tasks;
namespace Entities
{
/// <summary>
/// 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
/// </summary>
[Table("Questions")]
public class QuestionEntity
{
/// <summary>
/// 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
/// </summary>
[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; }

@ -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 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 answers :
/// convert model to DTO, model to Entity, ...
/// and equality protocols
/// </summary>
public static class AnswerExtensionMethods
{
/// <summary>
/// convet a dto answer into a model answer
/// </summary>
/// <param name="a">the dto answer to convert</param>
/// <returns>the model answer that correspond</returns>
public static Answer ToModel(this AnswerDto a)
{
return new Answer(a.Content, a.Id);
}
/// <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>
// conversion methods
public static Answer ToModel(this AnswerEntity a)
{
return new Answer(a.Content, 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>
=> 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 };
/// <summary>
/// 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>
// reuse other methods
public static AnswerDto ToDto(this AnswerEntity a)
{
return new AnswerDto
{
Content = a.Content,
Id = a.Id
};
}
/// <summary>
/// equality protocole
/// </summary>
/// <param name="obj">an object</param>
/// <returns>
/// 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
/// </returns>
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());
}
}

@ -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,25 +7,23 @@ using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// define an administrator
/// attributes :
/// id : identifier in the database
/// username : username for a administrator
/// hashedPassword : hash of the password of the administrator
/// </summary>
public class Administrator
{
/// <summary>
/// define an administrator
/// attributes :
/// id : identifier in the database
/// username : username for a administrator
/// hashedPassword : hash of the password of the administrator
/// </summary>
private int id;
private uint id;
private string? username;
private string? hashedPassword;
/// <summary>
/// getters and setters for attributes
/// </summary>
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
/// <param name="username">the username 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>
public Administrator(string username, string hashedPassword, int id = -1)
public Administrator(string username, string hashedPassword, uint id = 0)
{
this.Username = username;
this.HashedPassword = hashedPassword;

@ -3,44 +3,42 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Model
{
/// <summary>
/// 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
/// </summary>
public class Answer
{
/// <summary>
/// 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
/// </summary>
private int id;
private uint id;
private string? content;
private int idQuestion;
private uint idQuestion;
public Question? question;
/// <summary>
/// getters and setters for attributes
/// </summary>
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; }
}
/// <summary>
/// constructor of an answer
@ -48,7 +46,7 @@ namespace Model
/// <param name="content">the content of the answer</param>
/// <param name="id">the id in the database</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;
Id = id;

@ -7,23 +7,21 @@ using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// define a mathematical chapter or thematic
/// attributes :
/// id : identifier in the database
/// name : name of the chapter
/// </summary>
public class Chapter
{
/// <summary>
/// define a mathematical chapter or thematic
/// attributes :
/// id : identifier in the database
/// name : name of the chapter
/// </summary>
int id;
uint id;
string? name;
/// <summary>
/// getters and setters for attributs
/// </summary>
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
/// </summary>
/// <param name="name">name of the chapter</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;
Id = id;

@ -8,30 +8,28 @@ using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// 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
/// </summary>
public class Lobby
{
/// <summary>
/// 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
/// </summary>
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;
/// <summary>
/// getters and setters of attributes
/// </summary>
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
/// <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="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;
Creator = creator;
Password = password;
NbPlayers = nbPlayer;
NbPlayers = nbPlayers;
Id = id;
}
}

@ -7,23 +7,21 @@ using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// define a player
/// attributes :
/// id : identifier in the database
/// nickname : nickname for the player
/// hashedPassword : hashed of the password of the player
/// </summary>
public class Player
{
/// <summary>
/// define a player
/// attributes :
/// id : identifier in the database
/// nickname : nickname for the player
/// hashedPassword : hashed of the password of the player
/// </summary>
private int id;
private uint id;
private string? nickname;
private string? hashedPassword;
/// <summary>
/// getters and setters for attributes
/// </summary>
public int Id
// getters and setters for attributes
public uint Id
{
get => id;
private set { id = value; }
@ -45,7 +43,7 @@ namespace Model
/// <param name="nickname">nickname of the player</param>
/// <param name="hashedPassword">hash of the password 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;
HashedPassword = hashedPassword;

@ -8,73 +8,73 @@ using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// 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
/// </summary>
public class Question
{
/// <summary>
/// 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
/// </summary>
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;

Loading…
Cancel
Save