finalisation du dbcontext et des entitées
continuous-integration/drone/push Build is passing Details

API
Damien NORTIER 1 year ago
parent 4fa4c41be1
commit f972a3a9c9

@ -11,9 +11,12 @@ namespace DTOs
/// 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 string Content { get; set; } = null!;
public int? IdQuestion { get; set; }
public QuestionDto Question { get; set; } = null!;
}
}

@ -17,11 +17,13 @@ namespace DTOs
/// 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 string Name { get; set; } = null!;
public string Password { get; set; } = null!;
public int NbPlayers { get; set; }
public int? IdCreator { get; set; }
public PlayerDto Creator { get; set; } = null!;
}
}

@ -19,6 +19,8 @@ namespace DTOs
/// 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 string Content { get; set; } = null!;
@ -26,5 +28,7 @@ namespace DTOs
public int NbFalls { get; set; }
public int? IdChapter { get; set; }
public int? IdAnswerGood { get; set; }
public ChapterDto? Chapter { get; set; }
public AnswerDto? AnswerGood { get; set; }
}
}

@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>

@ -0,0 +1,265 @@
// <auto-generated />
using System;
using DbConnectionLibrairie;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DbConnectionLibrairie.Migrations
{
[DbContext(typeof(MyDbContext))]
[Migration("20240226094705_m1")]
partial class m1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.AdministratorEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Administrators");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("IdQuestion")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdQuestion");
b.ToTable("Answers");
});
modelBuilder.Entity("Entities.ChapterEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Chapters");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint?>("IdCreator")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("NbPlayers")
.HasColumnType("INTEGER");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("IdCreator");
b.ToTable("Lobbies");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.Property<uint>("IdLobby")
.HasColumnType("INTEGER");
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdLobby", "IdPlayer");
b.HasIndex("IdPlayer");
b.ToTable("Use");
});
modelBuilder.Entity("Entities.PlayerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdPlayer", "IdChapter");
b.HasIndex("IdChapter");
b.ToTable("Play");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<byte>("Difficulty")
.HasColumnType("INTEGER");
b.Property<uint?>("IdAnswerGood")
.HasColumnType("INTEGER");
b.Property<uint?>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("NbFalls")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdAnswerGood");
b.HasIndex("IdChapter");
b.ToTable("Questions");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.HasOne("Entities.QuestionEntity", "Question")
.WithMany()
.HasForeignKey("IdQuestion")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.HasOne("Entities.PlayerEntity", "Creator")
.WithMany()
.HasForeignKey("IdCreator");
b.Navigation("Creator");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.HasOne("Entities.LobbyEntity", "Lobby")
.WithMany()
.HasForeignKey("IdLobby")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("IdPlayer")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lobby");
b.Navigation("Player");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.HasOne("Entities.ChapterEntity", "Chapter")
.WithMany()
.HasForeignKey("IdChapter")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("IdPlayer")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Chapter");
b.Navigation("Player");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.HasOne("Entities.AnswerEntity", "AnswerGood")
.WithMany()
.HasForeignKey("IdAnswerGood");
b.HasOne("Entities.ChapterEntity", "Chapter")
.WithMany()
.HasForeignKey("IdChapter");
b.Navigation("AnswerGood");
b.Navigation("Chapter");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,237 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DbConnectionLibrairie.Migrations
{
/// <inheritdoc />
public partial class m1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Administrators",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column<string>(type: "TEXT", nullable: false),
HashedPassword = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Administrators", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Chapters",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Chapters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Nickname = table.Column<string>(type: "TEXT", nullable: false),
HashedPassword = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Players", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Lobbies",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", nullable: false),
Password = table.Column<string>(type: "TEXT", nullable: false),
NbPlayers = table.Column<uint>(type: "INTEGER", nullable: false),
IdCreator = table.Column<uint>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Lobbies", x => x.Id);
table.ForeignKey(
name: "FK_Lobbies_Players_IdCreator",
column: x => x.IdCreator,
principalTable: "Players",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Play",
columns: table => new
{
IdChapter = table.Column<uint>(type: "INTEGER", nullable: false),
IdPlayer = table.Column<uint>(type: "INTEGER", nullable: false),
MaxScore = table.Column<uint>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Play", x => new { x.IdPlayer, x.IdChapter });
table.ForeignKey(
name: "FK_Play_Chapters_IdChapter",
column: x => x.IdChapter,
principalTable: "Chapters",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Play_Players_IdPlayer",
column: x => x.IdPlayer,
principalTable: "Players",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Use",
columns: table => new
{
IdLobby = table.Column<uint>(type: "INTEGER", nullable: false),
IdPlayer = table.Column<uint>(type: "INTEGER", nullable: false),
MaxScore = table.Column<uint>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Use", x => new { x.IdLobby, x.IdPlayer });
table.ForeignKey(
name: "FK_Use_Lobbies_IdLobby",
column: x => x.IdLobby,
principalTable: "Lobbies",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Use_Players_IdPlayer",
column: x => x.IdPlayer,
principalTable: "Players",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Answers",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Content = table.Column<string>(type: "TEXT", nullable: false),
IdQuestion = table.Column<uint>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Answers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Questions",
columns: table => new
{
Id = table.Column<uint>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Content = table.Column<string>(type: "TEXT", nullable: false),
Difficulty = table.Column<byte>(type: "INTEGER", nullable: false),
NbFalls = table.Column<uint>(type: "INTEGER", nullable: false),
IdChapter = table.Column<uint>(type: "INTEGER", nullable: true),
IdAnswerGood = table.Column<uint>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Questions", x => x.Id);
table.ForeignKey(
name: "FK_Questions_Answers_IdAnswerGood",
column: x => x.IdAnswerGood,
principalTable: "Answers",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Questions_Chapters_IdChapter",
column: x => x.IdChapter,
principalTable: "Chapters",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Answers_IdQuestion",
table: "Answers",
column: "IdQuestion");
migrationBuilder.CreateIndex(
name: "IX_Lobbies_IdCreator",
table: "Lobbies",
column: "IdCreator");
migrationBuilder.CreateIndex(
name: "IX_Play_IdChapter",
table: "Play",
column: "IdChapter");
migrationBuilder.CreateIndex(
name: "IX_Questions_IdAnswerGood",
table: "Questions",
column: "IdAnswerGood");
migrationBuilder.CreateIndex(
name: "IX_Questions_IdChapter",
table: "Questions",
column: "IdChapter");
migrationBuilder.CreateIndex(
name: "IX_Use_IdPlayer",
table: "Use",
column: "IdPlayer");
migrationBuilder.AddForeignKey(
name: "FK_Answers_Questions_IdQuestion",
table: "Answers",
column: "IdQuestion",
principalTable: "Questions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Answers_Questions_IdQuestion",
table: "Answers");
migrationBuilder.DropTable(
name: "Administrators");
migrationBuilder.DropTable(
name: "Play");
migrationBuilder.DropTable(
name: "Use");
migrationBuilder.DropTable(
name: "Lobbies");
migrationBuilder.DropTable(
name: "Players");
migrationBuilder.DropTable(
name: "Questions");
migrationBuilder.DropTable(
name: "Answers");
migrationBuilder.DropTable(
name: "Chapters");
}
}
}

@ -0,0 +1,262 @@
// <auto-generated />
using System;
using DbConnectionLibrairie;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DbConnectionLibrairie.Migrations
{
[DbContext(typeof(MyDbContext))]
partial class MyDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.AdministratorEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Administrators");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("IdQuestion")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdQuestion");
b.ToTable("Answers");
});
modelBuilder.Entity("Entities.ChapterEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Chapters");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<uint?>("IdCreator")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<uint>("NbPlayers")
.HasColumnType("INTEGER");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("IdCreator");
b.ToTable("Lobbies");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.Property<uint>("IdLobby")
.HasColumnType("INTEGER");
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdLobby", "IdPlayer");
b.HasIndex("IdPlayer");
b.ToTable("Use");
});
modelBuilder.Entity("Entities.PlayerEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("HashedPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Nickname")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Players");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.Property<uint>("IdPlayer")
.HasColumnType("INTEGER");
b.Property<uint>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("MaxScore")
.HasColumnType("INTEGER");
b.HasKey("IdPlayer", "IdChapter");
b.HasIndex("IdChapter");
b.ToTable("Play");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.Property<uint?>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<byte>("Difficulty")
.HasColumnType("INTEGER");
b.Property<uint?>("IdAnswerGood")
.HasColumnType("INTEGER");
b.Property<uint?>("IdChapter")
.HasColumnType("INTEGER");
b.Property<uint>("NbFalls")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("IdAnswerGood");
b.HasIndex("IdChapter");
b.ToTable("Questions");
});
modelBuilder.Entity("Entities.AnswerEntity", b =>
{
b.HasOne("Entities.QuestionEntity", "Question")
.WithMany()
.HasForeignKey("IdQuestion")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("Entities.LobbyEntity", b =>
{
b.HasOne("Entities.PlayerEntity", "Creator")
.WithMany()
.HasForeignKey("IdCreator");
b.Navigation("Creator");
});
modelBuilder.Entity("Entities.LobbyEntityPlayerEntity", b =>
{
b.HasOne("Entities.LobbyEntity", "Lobby")
.WithMany()
.HasForeignKey("IdLobby")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("IdPlayer")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Lobby");
b.Navigation("Player");
});
modelBuilder.Entity("Entities.PlayerEntityChapterEntity", b =>
{
b.HasOne("Entities.ChapterEntity", "Chapter")
.WithMany()
.HasForeignKey("IdChapter")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("IdPlayer")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Chapter");
b.Navigation("Player");
});
modelBuilder.Entity("Entities.QuestionEntity", b =>
{
b.HasOne("Entities.AnswerEntity", "AnswerGood")
.WithMany()
.HasForeignKey("IdAnswerGood");
b.HasOne("Entities.ChapterEntity", "Chapter")
.WithMany()
.HasForeignKey("IdChapter");
b.Navigation("AnswerGood");
b.Navigation("Chapter");
});
#pragma warning restore 612, 618
}
}
}

@ -11,6 +11,8 @@ namespace DbConnectionLibrairie
public DbSet<LobbyEntity> Lobbies { get; set; }
public DbSet<PlayerEntity> Players { get; set; }
public DbSet<QuestionEntity> Questions { get; set; }
public DbSet<LobbyEntityPlayerEntity> Use { get; set; }
public DbSet<PlayerEntityChapterEntity> Play { get; set; }
public MyDbContext()
{ }
@ -25,5 +27,18 @@ namespace DbConnectionLibrairie
options.UseSqlite(@"Data source = database.db");
}
}
/// <summary>
/// function overrided OnModelCreating :
/// initialise composed primary keys
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LobbyEntityPlayerEntity>().HasKey(u => new { u.IdLobby, u.IdPlayer });
modelBuilder.Entity<PlayerEntityChapterEntity>().HasKey(u => new { u.IdPlayer, u.IdChapter });
base.OnModelCreating(modelBuilder);
}
}
}

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
[Table("Administrators")]
public class AdministratorEntity
{
/// <summary>
@ -17,7 +14,7 @@ namespace Entities
/// HashedPassword : hash of the password of the administrator
/// </summary>
[Key]
public int? Id { get; set; }
public uint? Id { get; set; }
public string Username { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
[Table("Answers")]
public class AnswerEntity
{
/// <summary>
@ -11,12 +12,15 @@ namespace Entities
/// 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 int? Id { get; set; }
public uint? Id { get; set; }
public string Content { get; set; } = null!;
[ForeignKey(nameof(QuestionEntity))]
public int? IdQuestion { get; set; }
[ForeignKey(nameof(Question))]
public uint IdQuestion { get; set; }
public QuestionEntity Question { get; set; } = null!;
}
}

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
[Table("Chapters")]
public class ChapterEntity
{
/// <summary>
@ -16,7 +13,7 @@ namespace Entities
/// Name : name of the chapter
/// </summary>
[Key]
public int? Id { get; set; }
public uint? Id { get; set; }
public string Name { get; set; } = null!;
}
}

@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace Entities
{
[Table("Lobbies")]
public class LobbyEntity
{
/// <summary>
@ -17,14 +14,17 @@ namespace Entities
/// 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 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 uint NbPlayers { get; set; }
[ForeignKey(nameof(PlayerEntity))]
public int? IdCreator { get; set; }
[ForeignKey(nameof(Creator))]
public uint? IdCreator { get; set; }
public PlayerEntity Creator { get; set; } = null!;
}
}

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
[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; }
[ForeignKey(nameof(Player))]
public uint IdPlayer { get; set; }
public LobbyEntity Lobby { get; set; } = null!;
public PlayerEntity Player { get; set; } = null!;
public uint MaxScore { get; set; }
}
}

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities
{
[Table("Players")]
public class PlayerEntity
{
/// <summary>
@ -17,7 +14,7 @@ namespace Entities
/// HashedPassword : hashed of the password of the player
/// </summary>
[Key]
public int? Id { get; set; }
public uint? Id { get; set; }
public string Nickname { get; set; } = null!;
public string HashedPassword { get; set; } = null!;
}

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entities
{
[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; }
[ForeignKey(nameof(Player))]
public uint IdPlayer { get; set; }
public ChapterEntity Chapter { get; set; } = null!;
public PlayerEntity Player { get; set; } = null!;
public uint MaxScore { get; set; }
}
}

@ -8,6 +8,7 @@ using System.Threading.Tasks;
namespace Entities
{
[Table("Questions")]
public class QuestionEntity
{
/// <summary>
@ -19,17 +20,24 @@ namespace Entities
/// 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 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; }
[AllowedValues(1, 2, 3)]
public byte Difficulty { get; set; }
public uint NbFalls { get; set; }
[ForeignKey(nameof(ChapterEntity))]
public int? IdChapter { get; set; }
[ForeignKey(nameof(Chapter))]
public uint? IdChapter { get; set; }
[ForeignKey(nameof(AnswerEntity))]
public int? IdAnswerGood { get; set; }
[ForeignKey(nameof(AnswerGood))]
public uint? IdAnswerGood { get; set; }
public ChapterEntity? Chapter { get; set; }
public AnswerEntity? AnswerGood { get; set; }
}
}

@ -11,10 +11,12 @@ namespace Model
/// 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 string? content;
private int idQuestion;
public Question? question;
/// <summary>
/// getters and setters for attributes
@ -34,17 +36,23 @@ namespace Model
get => idQuestion == -1 ? null : idQuestion; // null = no idQuestion
private set { idQuestion = value < -1 || value == null ? -1 : value.Value; }
}
public Question? Question
{
get => question;
private set { question = value; IdQuestion = value == null ? -1 : value.Id; }
}
/// <summary>
/// constructor of an answer
/// </summary>
/// <param name="content">the content of the answer</param>
/// <param name="id">the id in the database</param>
/// <param name="idQuestion">the id of the question which it answer to</param>
public Answer(string content, int? idQuestion = null, int? id = null)
/// <param name="question">the question which it answer to</param>
public Answer(string content, Question? question = null, int? id = null)
{
Content = content;
Id = id;
IdQuestion = idQuestion;
Question = question;
}
}

@ -17,12 +17,14 @@ namespace Model
/// 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 string? name;
private string? password;
private int nbPlayers;
private int idCreator;
private Player creator;
/// <summary>
/// getters and setters of attributes
/// </summary>
@ -51,19 +53,24 @@ namespace Model
get => idCreator == -1 ? null : id;
private set { idCreator = value == null || value < -1 ? -1 : value.Value; }
}
public Player Creator
{
get => creator;
set { creator = value; idCreator = value.Id; }
}
/// <summary>
/// constructor of a lobby
/// </summary>
/// <param name="name">the name of the lobby</param>
/// <param name="idCreator">the id of the creator</param>
/// <param name="creator">the creator</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="id">the id of the lobby</param>
public Lobby(string name, int idCreator, string password = "", int nbPlayer = 0, int? id = null)
public Lobby(string name, Player creator, string password = "", int nbPlayer = 0, int? id = null)
{
Name = name;
IdCreator = idCreator;
Creator = creator;
Password = password;
NbPlayers = nbPlayer;
Id = id;

@ -23,10 +23,10 @@ namespace Model
/// <summary>
/// getters and setters for attributes
/// </summary>
public int? Id
public int Id
{
get => id == -1 ? null : id;
private set { id = value == null || value < -1 ? -1 : value.Value; }
get => id;
private set { id = value; }
}
public string Nickname
{

@ -19,6 +19,8 @@ namespace Model
/// 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 string? content;
@ -26,6 +28,8 @@ namespace Model
private int nbFalls;
private int idChapter;
private int idAnswerGood;
private Chapter? chapter;
private Answer? answerGood;
public int? Id
{
@ -58,14 +62,26 @@ namespace Model
set { idAnswerGood = value == null || value < -1 ? -1 : value.Value; }
}
public Question(string content, int idChapter = -1, int id = -1, int idAnswerGood = -1)
public Chapter? Chapter
{
get => chapter;
set { chapter = value; IdChapter = value == null ? -1 : value.Id; }
}
public Answer? AnswerGood
{
get => answerGood;
set { answerGood = value; IdAnswerGood = value == null ? -1 : value.Id; }
}
public Question(string content, Chapter? chapter = null, int id = -1, Answer? answerGood = null)
{
Id = id;
Content = content;
Difficulty = 1;
NbFalls = 0;
IdChapter = idChapter;
IdAnswerGood = idAnswerGood;
Chapter = chapter;
AnswerGood = answerGood;
}
}
}

Loading…
Cancel
Save