ajout méthodes player manager (pas tester mais coder)
continuous-integration/drone/push Build is failing Details

dbdatamanager
Maxence LANONE 2 years ago
parent 8619817ac5
commit cf5d5bd695

@ -3,7 +3,7 @@
namespace DbDataManager; namespace DbDataManager;
public class DbDataManager : IDataManager public class DbDataManager : IDataManager
{ {
public IPlayersManager PlayersMgr => throw new NotImplementedException(); public IPlayersManager PlayersMgr => new PlayersManager();
public IGamesManager GamesMgr => throw new NotImplementedException(); public IGamesManager GamesMgr => throw new NotImplementedException();

@ -8,5 +8,12 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Trek12_Lib\EntityFrameWorkLib.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Mapper\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Mapper\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DbDataManager
{
static class Extensions
{
internal static Task<IEnumerable<T?>> GetItemsWithFilterAndOrdering<T>(this IEnumerable<T> collection,
Func<T, bool> filter, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
IEnumerable<T> temp = collection;
temp = temp.Where(item => filter(item));
if (orderingPropertyName != null)
{
var prop = typeof(T).GetProperty(orderingPropertyName!);
if (prop != null)
{
temp = descending ? temp.OrderByDescending(item => prop.GetValue(item))
: temp.OrderBy(item => prop.GetValue(item));
}
}
return Task.FromResult<IEnumerable<T?>>(temp.Skip(index * count).Take(count));
}
internal static Task<int> GetNbItemsWithFilter<T>(this IEnumerable<T> collection, Func<T, bool> filter)
{
return Task.FromResult(collection.Count(item => filter(item)));
}
internal static Task<T?> AddItem<T>(this IList<T> collection, T? item)
{
if (item == null || collection.Contains(item))
{
return Task.FromResult(default(T));
}
collection.Add(item);
return Task.FromResult<T?>(item);
}
internal static Task<bool> DeleteItem<T>(this IList<T> collection, T? item)
{
if (item == null)
{
return Task.FromResult(false);
}
bool result = collection.Remove(item!);
return Task.FromResult(result);
}
internal static Task<T?> UpdateItem<T>(this IList<T> collection, T? oldItem, T? newItem)
{
if (oldItem == null || newItem == null) return Task.FromResult<T?>(default(T));
if (!collection.Contains(oldItem))
{
return Task.FromResult<T?>(default(T));
}
collection.Remove(oldItem!);
collection.Add(newItem!);
return Task.FromResult<T?>(newItem);
}
}
}

@ -0,0 +1,30 @@
using System;
using EntityFrameWorkLib;
using Model;
namespace DbDataManager.Mapper
{
public static class PlayerMapper
{
public static Player ToModel(this PlayerEntity playerEntity)
{
Player player = new Player(playerEntity.Pseudo, playerEntity.stats.ToModel(), playerEntity.PlayerId);
return player;
}
public static PlayerEntity ToEntity(this Player playerModel)
{
PlayerEntity player = new PlayerEntity
{
PlayerId = playerModel.Id,
Pseudo = playerModel.Pseudo,
stats = playerModel.Stats.ToEntity(),
};
player.stats.PlayerId = playerModel.Id;
return player;
}
}
}

@ -0,0 +1,40 @@
using System;
using EntityFrameWorkLib;
using Model;
namespace DbDataManager.Mapper
{
public static class StatsMapper
{
public static Stats ToModel(this StatsEntity statsEntity)
{
var stats = new Stats
{
Id = statsEntity.Id,
NbWin = statsEntity.NbWin,
NbPlayed = statsEntity.NbPlayed,
MaxZone = statsEntity.MaxZone,
MaxChain = statsEntity.MaxChain,
MaxPoints = statsEntity.MaxPoints
};
return stats;
}
public static StatsEntity ToEntity(this Stats statsModel)
{
var stats = new StatsEntity
{
Id = statsModel.Id,
MaxChain = statsModel.MaxChain,
MaxPoints = statsModel.MaxPoints,
MaxZone = statsModel.MaxZone,
NbPlayed = statsModel.NbPlayed,
NbWin = statsModel.NbWin,
};
return stats;
}
}
}

@ -0,0 +1,85 @@
using System;
using EntityFrameWorkLib;
using Model;
using DbDataManager.Mapper;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Data.SqlTypes;
namespace DbDataManager
{
public class PlayersManager : IPlayersManager
{
private TrekContext trekContext;
public async Task<Player?> AddItem(Player? item)
{
if (item == null)
{
return null;
}
var player = await trekContext.AddAsync<Player>(item);
await trekContext.SaveChangesAsync();
return player.Entity;
}
public async Task<bool> DeleteItem(Player? item)
{
if (item == null)
{
return false;
}
var deleteItem = trekContext.Remove<Player>(item);
await trekContext.SaveChangesAsync();
return true;
}
public async Task<IEnumerable<Player?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
IEnumerable<Player> players = trekContext.Players.Skip(index * count)
.Take(count)
.OrderBy(players => orderingPropertyName)
.Select(players => players.ToModel());
return players;
}
public Task<IEnumerable<Player?>> GetItemsById(int id)
{
return trekContext.Players.Select(player => player.ToModel()).GetItemsWithFilterAndOrdering(player => filterById(player, id),0,1);
}
private Func<Player, int, bool> filterById = (player, id) => player.Id.Equals(id);
public Task<IEnumerable<Player?>> GetItemsByPseudo(string charPseudo)
{
return trekContext.Players.Select(player => player.ToModel()).GetItemsWithFilterAndOrdering<Player>(player => filterByPseudo(player, charPseudo), 0, trekContext.Players.Count());
}
private Func<Player, string, bool> filterByPseudo = (player, substring) => player.Pseudo.Contains(substring, StringComparison.InvariantCultureIgnoreCase);
public Task<int> GetNbItems()
{
return Task.FromResult(trekContext.Players.Count());
}
public Task<int> GetNbItemsByPseudo(string charPseudo)
{
return trekContext.Players.Select(player => player.ToModel()).GetNbItemsWithFilter(player => filterByPseudo(player, charPseudo));
}
public Task<Player?> UpdateItem(Player? oldItem, Player? newItem)
{
if (oldItem == null || newItem == null) return Task.FromResult<Player?>(default(Player));
if (!trekContext.Players.Select(player => player.ToModel()).Contains(oldItem))
{
return Task.FromResult<Player?>(default(Player));
}
trekContext.Players.Remove(oldItem!.ToEntity());
trekContext.Players.AddAsync(newItem!.ToEntity());
return Task.FromResult<Player?>(newItem);
}
}
}

@ -6,11 +6,6 @@ namespace Stub
{ {
public StubData() public StubData()
{ {
//ChampionsMgr = new ChampionsManager(this);
//SkinsMgr = new SkinsManager(this);
//RunesMgr = new RunesManager(this);
//RunePagesMgr = new RunePagesManager(this);
PlayersMgr = new PlayersManager(this); PlayersMgr = new PlayersManager(this);
GamesMgr = new GamesManager(this); GamesMgr = new GamesManager(this);
GamesModeMgr = new GamesModeManager(this); GamesModeMgr = new GamesModeManager(this);

@ -23,7 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csp
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Stub", "Tests\Test_Stub\Test_Stub.csproj", "{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Stub", "Tests\Test_Stub\Test_Stub.csproj", "{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_Model", "Tests\Test_Model\Test_Model.csproj", "{593766AA-8E2A-4B3D-A299-8E45F5C19C18}" Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "Test_Model", "Tests\Test_Model\Test_Model.csproj", "{CFA6848A-2A65-49CA-BE0B-3759F52B85E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbDataManager", "DbDataManager\DbDataManager.csproj", "{57F6555B-462D-4ED1-89C9-495EC7111218}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -63,10 +65,14 @@ Global
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Debug|Any CPU.Build.0 = Debug|Any CPU {5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Release|Any CPU.ActiveCfg = Release|Any CPU {5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Release|Any CPU.Build.0 = Release|Any CPU {5A1D87FF-E82F-43FF-AC5C-59659B91D5B8}.Release|Any CPU.Build.0 = Release|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CFA6848A-2A65-49CA-BE0B-3759F52B85E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Debug|Any CPU.Build.0 = Debug|Any CPU {CFA6848A-2A65-49CA-BE0B-3759F52B85E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Release|Any CPU.ActiveCfg = Release|Any CPU {CFA6848A-2A65-49CA-BE0B-3759F52B85E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{593766AA-8E2A-4B3D-A299-8E45F5C19C18}.Release|Any CPU.Build.0 = Release|Any CPU {CFA6848A-2A65-49CA-BE0B-3759F52B85E3}.Release|Any CPU.Build.0 = Release|Any CPU
{57F6555B-462D-4ED1-89C9-495EC7111218}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57F6555B-462D-4ED1-89C9-495EC7111218}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57F6555B-462D-4ED1-89C9-495EC7111218}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57F6555B-462D-4ED1-89C9-495EC7111218}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -76,7 +82,7 @@ Global
{6EC6383D-10E8-44E1-8EDD-EF4DF460A9B1} = {C75DF644-C41F-4A08-8B69-C8554204AC72} {6EC6383D-10E8-44E1-8EDD-EF4DF460A9B1} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
{5E45E953-4FCC-42B6-9F22-15108D002D78} = {B1585816-FCBB-484F-A1AA-C7AEB501C39B} {5E45E953-4FCC-42B6-9F22-15108D002D78} = {B1585816-FCBB-484F-A1AA-C7AEB501C39B}
{5A1D87FF-E82F-43FF-AC5C-59659B91D5B8} = {C75DF644-C41F-4A08-8B69-C8554204AC72} {5A1D87FF-E82F-43FF-AC5C-59659B91D5B8} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
{593766AA-8E2A-4B3D-A299-8E45F5C19C18} = {C75DF644-C41F-4A08-8B69-C8554204AC72} {CFA6848A-2A65-49CA-BE0B-3759F52B85E3} = {C75DF644-C41F-4A08-8B69-C8554204AC72}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105} SolutionGuid = {4D47853B-D1A3-49A5-84BA-CD2DC65FD105}

@ -11,14 +11,14 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFrameWorkLib.Migrations namespace EntityFrameWorkLib.Migrations
{ {
[DbContext(typeof(TrekContext))] [DbContext(typeof(TrekContext))]
[Migration("20230320170231_AllMigrations")] [Migration("20230411093944_MyMigration")]
partial class AllMigrations partial class MyMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b => modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{ {
@ -26,11 +26,16 @@ namespace EntityFrameWorkLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("GrilleId")
.HasColumnType("INTEGER");
b.Property<int>("Value") b.Property<int>("Value")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("CaseId"); b.HasKey("CaseId");
b.HasIndex("GrilleId");
b.ToTable("Case"); b.ToTable("Case");
}); });
@ -47,14 +52,18 @@ namespace EntityFrameWorkLib.Migrations
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("NbPlayers") b.Property<int>("NbPlayers")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.HasKey("GameId"); b.HasKey("GameId");
b.HasIndex("PlayerId");
b.ToTable("Game"); b.ToTable("Game");
}); });
@ -87,52 +96,62 @@ namespace EntityFrameWorkLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("MaxPoints") b.Property<string>("Pseudo")
.HasColumnType("INTEGER"); .HasColumnType("TEXT");
b.Property<int>("MaxZone") b.HasKey("PlayerId");
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed") b.ToTable("Players");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.Property<int>("GameId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("NbPoints") b.Property<int>("PlayerId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("NbWin") b.Property<int>("NbPointsTotal")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("Pseudo") b.HasKey("GameId", "PlayerId");
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId"); b.HasIndex("PlayerId");
b.ToTable("Players"); b.ToTable("Score");
}); });
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => modelBuilder.Entity("EntityFrameWorkLib.StatsEntity", b =>
{ {
b.Property<int>("ScoreId") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("GameId") b.Property<int>("MaxChain")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("NbPoints") b.Property<int>("MaxPoints")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("PlayerId") b.Property<int>("MaxZone")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("ScoreId"); b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.HasIndex("GameId"); b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.HasIndex("PlayerId"); b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.ToTable("Score"); b.HasKey("Id");
b.HasIndex("PlayerId")
.IsUnique();
b.ToTable("Stats");
}); });
modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b => modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b =>
@ -152,10 +171,32 @@ namespace EntityFrameWorkLib.Migrations
b.ToTable("Turn"); b.ToTable("Turn");
}); });
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{
b.HasOne("EntityFrameWorkLib.GrilleEntity", "Grille")
.WithMany("Cases")
.HasForeignKey("GrilleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Grille");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{ {
b.HasOne("EntityFrameWorkLib.GameEntity", "Game") b.HasOne("EntityFrameWorkLib.GameEntity", "Game")
.WithMany() .WithMany("Scores")
.HasForeignKey("GameId") .HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -170,6 +211,33 @@ namespace EntityFrameWorkLib.Migrations
b.Navigation("Player"); b.Navigation("Player");
}); });
modelBuilder.Entity("EntityFrameWorkLib.StatsEntity", b =>
{
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithOne("stats")
.HasForeignKey("EntityFrameWorkLib.StatsEntity", "PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.Navigation("Scores");
});
modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b =>
{
b.Navigation("Cases");
});
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Navigation("stats")
.IsRequired();
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

@ -6,101 +6,132 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace EntityFrameWorkLib.Migrations namespace EntityFrameWorkLib.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class AllMigrations : Migration public partial class MyMigration : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Case", name: "Grille",
columns: table => new columns: table => new
{ {
CaseId = table.Column<int>(type: "INTEGER", nullable: false) GrilleId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
Value = table.Column<int>(type: "INTEGER", nullable: false) NbChains = table.Column<int>(type: "INTEGER", nullable: false),
NbZones = table.Column<int>(type: "INTEGER", nullable: false),
MaxChain = table.Column<int>(type: "INTEGER", nullable: false),
MaxZone = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Case", x => x.CaseId); table.PrimaryKey("PK_Grille", x => x.GrilleId);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Game", name: "Players",
columns: table => new columns: table => new
{ {
GameId = table.Column<int>(type: "INTEGER", nullable: false) PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
Duration = table.Column<TimeSpan>(type: "TEXT", nullable: false), Pseudo = table.Column<string>(type: "TEXT", nullable: true)
Date = table.Column<DateOnly>(type: "TEXT", nullable: false),
NbPlayers = table.Column<int>(type: "INTEGER", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Game", x => x.GameId); table.PrimaryKey("PK_Players", x => x.PlayerId);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Grille", name: "Turn",
columns: table => new columns: table => new
{ {
GrilleId = table.Column<int>(type: "INTEGER", nullable: false) TurnId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
NbChains = table.Column<int>(type: "INTEGER", nullable: false), DiceValue1 = table.Column<int>(type: "INTEGER", nullable: false),
NbZones = table.Column<int>(type: "INTEGER", nullable: false), DiceValue2 = table.Column<int>(type: "INTEGER", nullable: false)
MaxChain = table.Column<int>(type: "INTEGER", nullable: false),
MaxZone = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Grille", x => x.GrilleId); table.PrimaryKey("PK_Turn", x => x.TurnId);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Players", name: "Case",
columns: table => new columns: table => new
{ {
PlayerId = table.Column<int>(type: "INTEGER", nullable: false) CaseId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false), GrilleId = table.Column<int>(type: "INTEGER", nullable: false),
NbWin = table.Column<int>(type: "INTEGER", nullable: false), Value = table.Column<int>(type: "INTEGER", nullable: false)
NbPlayed = table.Column<int>(type: "INTEGER", nullable: false),
MaxZone = table.Column<int>(type: "INTEGER", nullable: false),
MaxPoints = table.Column<int>(type: "INTEGER", nullable: false),
NbPoints = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Players", x => x.PlayerId); table.PrimaryKey("PK_Case", x => x.CaseId);
table.ForeignKey(
name: "FK_Case_Grille_GrilleId",
column: x => x.GrilleId,
principalTable: "Grille",
principalColumn: "GrilleId",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Turn", name: "Game",
columns: table => new columns: table => new
{ {
TurnId = table.Column<int>(type: "INTEGER", nullable: false) GameId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
DiceValue1 = table.Column<int>(type: "INTEGER", nullable: false), Duration = table.Column<TimeSpan>(type: "TEXT", nullable: false),
DiceValue2 = table.Column<int>(type: "INTEGER", nullable: false) Date = table.Column<DateOnly>(type: "TEXT", nullable: false),
NbPlayers = table.Column<int>(type: "INTEGER", nullable: false),
PlayerId = table.Column<int>(type: "INTEGER", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Turn", x => x.TurnId); table.PrimaryKey("PK_Game", x => x.GameId);
table.ForeignKey(
name: "FK_Game_Players_PlayerId",
column: x => x.PlayerId,
principalTable: "Players",
principalColumn: "PlayerId",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Score", name: "Stats",
columns: table => new columns: table => new
{ {
ScoreId = table.Column<int>(type: "INTEGER", nullable: false) Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true), .Annotation("Sqlite:Autoincrement", true),
NbPoints = table.Column<int>(type: "INTEGER", nullable: false), NbWin = table.Column<int>(type: "INTEGER", nullable: false),
GameId = table.Column<int>(type: "INTEGER", nullable: false), NbPlayed = table.Column<int>(type: "INTEGER", nullable: false),
MaxChain = table.Column<int>(type: "INTEGER", nullable: false),
MaxZone = table.Column<int>(type: "INTEGER", nullable: false),
MaxPoints = table.Column<int>(type: "INTEGER", nullable: false),
PlayerId = table.Column<int>(type: "INTEGER", nullable: false) PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Score", x => x.ScoreId); table.PrimaryKey("PK_Stats", x => x.Id);
table.ForeignKey(
name: "FK_Stats_Players_PlayerId",
column: x => x.PlayerId,
principalTable: "Players",
principalColumn: "PlayerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Score",
columns: table => new
{
GameId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerId = table.Column<int>(type: "INTEGER", nullable: false),
NbPointsTotal = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Score", x => new { x.GameId, x.PlayerId });
table.ForeignKey( table.ForeignKey(
name: "FK_Score_Game_GameId", name: "FK_Score_Game_GameId",
column: x => x.GameId, column: x => x.GameId,
@ -116,14 +147,25 @@ namespace EntityFrameWorkLib.Migrations
}); });
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Score_GameId", name: "IX_Case_GrilleId",
table: "Score", table: "Case",
column: "GameId"); column: "GrilleId");
migrationBuilder.CreateIndex(
name: "IX_Game_PlayerId",
table: "Game",
column: "PlayerId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Score_PlayerId", name: "IX_Score_PlayerId",
table: "Score", table: "Score",
column: "PlayerId"); column: "PlayerId");
migrationBuilder.CreateIndex(
name: "IX_Stats_PlayerId",
table: "Stats",
column: "PlayerId",
unique: true);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -133,14 +175,17 @@ namespace EntityFrameWorkLib.Migrations
name: "Case"); name: "Case");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Grille"); name: "Score");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Score"); name: "Stats");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Turn"); name: "Turn");
migrationBuilder.DropTable(
name: "Grille");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Game"); name: "Game");

@ -15,7 +15,7 @@ namespace EntityFrameWorkLib.Migrations
protected override void BuildModel(ModelBuilder modelBuilder) protected override void BuildModel(ModelBuilder modelBuilder)
{ {
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b => modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{ {
@ -23,11 +23,16 @@ namespace EntityFrameWorkLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("GrilleId")
.HasColumnType("INTEGER");
b.Property<int>("Value") b.Property<int>("Value")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("CaseId"); b.HasKey("CaseId");
b.HasIndex("GrilleId");
b.ToTable("Case"); b.ToTable("Case");
}); });
@ -44,14 +49,18 @@ namespace EntityFrameWorkLib.Migrations
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("NbPlayers") b.Property<int>("NbPlayers")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.HasKey("GameId"); b.HasKey("GameId");
b.HasIndex("PlayerId");
b.ToTable("Game"); b.ToTable("Game");
}); });
@ -84,52 +93,62 @@ namespace EntityFrameWorkLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("MaxPoints") b.Property<string>("Pseudo")
.HasColumnType("INTEGER"); .HasColumnType("TEXT");
b.Property<int>("MaxZone") b.HasKey("PlayerId");
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed") b.ToTable("Players");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.Property<int>("GameId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("NbPoints") b.Property<int>("PlayerId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("NbWin") b.Property<int>("NbPointsTotal")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("Pseudo") b.HasKey("GameId", "PlayerId");
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId"); b.HasIndex("PlayerId");
b.ToTable("Players"); b.ToTable("Score");
}); });
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => modelBuilder.Entity("EntityFrameWorkLib.StatsEntity", b =>
{ {
b.Property<int>("ScoreId") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("GameId") b.Property<int>("MaxChain")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("NbPoints") b.Property<int>("MaxPoints")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("PlayerId") b.Property<int>("MaxZone")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.HasKey("ScoreId"); b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.HasIndex("GameId"); b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.HasIndex("PlayerId"); b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.ToTable("Score"); b.HasKey("Id");
b.HasIndex("PlayerId")
.IsUnique();
b.ToTable("Stats");
}); });
modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b => modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b =>
@ -149,10 +168,32 @@ namespace EntityFrameWorkLib.Migrations
b.ToTable("Turn"); b.ToTable("Turn");
}); });
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{
b.HasOne("EntityFrameWorkLib.GrilleEntity", "Grille")
.WithMany("Cases")
.HasForeignKey("GrilleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Grille");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b => modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{ {
b.HasOne("EntityFrameWorkLib.GameEntity", "Game") b.HasOne("EntityFrameWorkLib.GameEntity", "Game")
.WithMany() .WithMany("Scores")
.HasForeignKey("GameId") .HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -167,6 +208,33 @@ namespace EntityFrameWorkLib.Migrations
b.Navigation("Player"); b.Navigation("Player");
}); });
modelBuilder.Entity("EntityFrameWorkLib.StatsEntity", b =>
{
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithOne("stats")
.HasForeignKey("EntityFrameWorkLib.StatsEntity", "PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Player");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.Navigation("Scores");
});
modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b =>
{
b.Navigation("Cases");
});
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Navigation("stats")
.IsRequired();
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

@ -10,10 +10,7 @@ namespace EntityFrameWorkLib
[DatabaseGenerated(DatabaseGeneratedOption.Identity)] [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PlayerId { get; set; } public int PlayerId { get; set; }
public string? Pseudo { get; set; } public string? Pseudo { get; set; }
public int NbWin { get; set; } public StatsEntity stats { get; set; }
public int NbPlayed { get; set; }
public int MaxZone { get; set; }
public int MaxPoints { get; set; }
} }
} }

@ -0,0 +1,17 @@
using System;
namespace EntityFrameWorkLib
{
public class StatsEntity
{
public int Id { get; set; }
public int NbWin { get; set; }
public int NbPlayed { get; set; }
public int MaxChain { get; set; }
public int MaxZone { get; set; }
public int MaxPoints { get; set; }
public int PlayerId { get; set; }
public PlayerEntity Player { get; set; }
}
}

@ -20,6 +20,8 @@ namespace EntityFrameWorkLib
public DbSet<ScoreEntity> Score { get; set; } public DbSet<ScoreEntity> Score { get; set; }
public DbSet<StatsEntity> Stats { get; set; }
public TrekContext() { } public TrekContext() { }
public TrekContext(DbContextOptions<TrekContext> options) public TrekContext(DbContextOptions<TrekContext> options)
: base(options) : base(options)
@ -78,6 +80,11 @@ namespace EntityFrameWorkLib
.WithOne(c => c.Grille) .WithOne(c => c.Grille)
.HasForeignKey(c => c.GrilleId); .HasForeignKey(c => c.GrilleId);
modelBuilder.Entity<PlayerEntity>() //l'entité Player...
.HasOne(n => n.stats) //a une propriété obligatoire stats...
.WithOne(c => c.Player) //reliée à la propriété Player de Stats...
.HasForeignKey<StatsEntity>(c => c.PlayerId);//dont la propriété Id est une Foreign Key
//Configuration des clés primaires et étrangères pour la table Participate //Configuration des clés primaires et étrangères pour la table Participate

Loading…
Cancel
Save