Merge branch 'master' of https://codefirst.iut.uca.fr/git/Trek_Prod/Trek12_API
continuous-integration/drone/push Build is passing Details

malanone/dbdatamanager
Aurelien PINTRAND 2 years ago
commit fe9affed75

@ -54,7 +54,7 @@ steps:
dockerfile: Sources/Trek12_API/Dockerfile
context: Sources/
registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/Trek_Prod/Trek12_API
repo: hub.codefirst.iut.uca.fr/trek_prod/trek12_api
username:
from_secret: SECRET_REGISTRY_USERNAME
password:
@ -64,7 +64,7 @@ steps:
- name: deploy-container
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest
environment:
IMAGENAME: hub.codefirst.iut.uca.fr/Trek_Prod/Trek12_API:latest
IMAGENAME: hub.codefirst.iut.uca.fr/trek_prod/trek12_api:latest
CONTAINERNAME: trek12api
COMMAND: create
OVERWRITE: true

@ -9,12 +9,15 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Model\Model.csproj" />
<ProjectReference Include="..\..\Trek12_Lib\EntityFrameWorkLib.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Microsoft.EntityFrameworkCore" />
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
<None Remove="Microsoft.EntityFrameworkCore.Sqlite" />
<None Remove="projet.Champions.db" />
<None Remove="projet.Score.db" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />

@ -1,53 +0,0 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DbConsole.Migrations
{
[DbContext(typeof(SQLiteContext))]
[Migration("20230212153116_MyMigration")]
partial class MyMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
#pragma warning restore 612, 618
}
}
}

@ -1,39 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DbConsole.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
NbWin = 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 =>
{
table.PrimaryKey("PK_Players", x => x.PlayerId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Players");
}
}
}

@ -0,0 +1,175 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DbConsole.Migrations
{
[DbContext(typeof(SQLiteContext))]
[Migration("20230320170448_AllMigrations")]
partial class AllMigrations
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{
b.Property<int>("CaseId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Value")
.HasColumnType("INTEGER");
b.HasKey("CaseId");
b.ToTable("Case");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.Property<int>("GameId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateOnly>("Date")
.HasColumnType("TEXT");
b.Property<TimeSpan>("Duration")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbPlayers")
.HasColumnType("INTEGER");
b.HasKey("GameId");
b.ToTable("Game");
});
modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b =>
{
b.Property<int>("GrilleId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxChain")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbChains")
.HasColumnType("INTEGER");
b.Property<int>("NbZones")
.HasColumnType("INTEGER");
b.HasKey("GrilleId");
b.ToTable("Grille");
});
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.Property<int>("ScoreId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GameId")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.HasKey("ScoreId");
b.HasIndex("GameId");
b.HasIndex("PlayerId");
b.ToTable("Score");
});
modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b =>
{
b.Property<int>("TurnId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("DiceValue1")
.HasColumnType("INTEGER");
b.Property<int>("DiceValue2")
.HasColumnType("INTEGER");
b.HasKey("TurnId");
b.ToTable("Turn");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.HasOne("EntityFrameWorkLib.GameEntity", "Game")
.WithMany()
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Player");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,151 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DbConsole.Migrations
{
/// <inheritdoc />
public partial class AllMigrations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Case",
columns: table => new
{
CaseId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Value = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Case", x => x.CaseId);
});
migrationBuilder.CreateTable(
name: "Game",
columns: table => new
{
GameId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Duration = table.Column<TimeSpan>(type: "TEXT", nullable: false),
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 =>
{
table.PrimaryKey("PK_Game", x => x.GameId);
});
migrationBuilder.CreateTable(
name: "Grille",
columns: table => new
{
GrilleId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
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 =>
{
table.PrimaryKey("PK_Grille", x => x.GrilleId);
});
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
NbWin = 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 =>
{
table.PrimaryKey("PK_Players", x => x.PlayerId);
});
migrationBuilder.CreateTable(
name: "Turn",
columns: table => new
{
TurnId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
DiceValue1 = table.Column<int>(type: "INTEGER", nullable: false),
DiceValue2 = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Turn", x => x.TurnId);
});
migrationBuilder.CreateTable(
name: "Score",
columns: table => new
{
ScoreId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
NbPoints = table.Column<int>(type: "INTEGER", nullable: false),
GameId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Score", x => x.ScoreId);
table.ForeignKey(
name: "FK_Score_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "GameId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Score_Players_PlayerId",
column: x => x.PlayerId,
principalTable: "Players",
principalColumn: "PlayerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Score_GameId",
table: "Score",
column: "GameId");
migrationBuilder.CreateIndex(
name: "IX_Score_PlayerId",
table: "Score",
column: "PlayerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Case");
migrationBuilder.DropTable(
name: "Grille");
migrationBuilder.DropTable(
name: "Score");
migrationBuilder.DropTable(
name: "Turn");
migrationBuilder.DropTable(
name: "Game");
migrationBuilder.DropTable(
name: "Players");
}
}
}

@ -1,4 +1,5 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@ -15,6 +16,67 @@ namespace DbConsole.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{
b.Property<int>("CaseId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Value")
.HasColumnType("INTEGER");
b.HasKey("CaseId");
b.ToTable("Case");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.Property<int>("GameId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateOnly>("Date")
.HasColumnType("TEXT");
b.Property<TimeSpan>("Duration")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbPlayers")
.HasColumnType("INTEGER");
b.HasKey("GameId");
b.ToTable("Game");
});
modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b =>
{
b.Property<int>("GrilleId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxChain")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbChains")
.HasColumnType("INTEGER");
b.Property<int>("NbZones")
.HasColumnType("INTEGER");
b.HasKey("GrilleId");
b.ToTable("Grille");
});
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
@ -44,6 +106,66 @@ namespace DbConsole.Migrations
b.ToTable("Players");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.Property<int>("ScoreId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GameId")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.HasKey("ScoreId");
b.HasIndex("GameId");
b.HasIndex("PlayerId");
b.ToTable("Score");
});
modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b =>
{
b.Property<int>("TurnId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("DiceValue1")
.HasColumnType("INTEGER");
b.Property<int>("DiceValue2")
.HasColumnType("INTEGER");
b.HasKey("TurnId");
b.ToTable("Turn");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.HasOne("EntityFrameWorkLib.GameEntity", "Game")
.WithMany()
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Player");
});
#pragma warning restore 612, 618
}
}

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
PlayerEntity p1 = new PlayerEntity
{
PlayerId = 0,
Pseudo = "Jax",
NbWin = 0,
NbPlayed = 0,
@ -11,8 +12,14 @@ PlayerEntity p1 = new PlayerEntity
NbPoints = 0
};
GameEntity g1 = new GameEntity
{
GameId = 1,
};
PlayerEntity p2 = new PlayerEntity
{
PlayerId = 0,
Pseudo = "Theo",
NbWin = 0,
NbPlayed = 0,
@ -21,12 +28,25 @@ PlayerEntity p2 = new PlayerEntity
NbPoints = 0
};
using (var context = new SQLiteContext())
/*using (var context = new SQLiteContext())
{
Console.WriteLine("Create and Insert new Champion");
Console.WriteLine("Create and Insert new Player");
context.Add(p1);
context.Add(p2);
context.SaveChanges();
}*/
using (var context = new SQLiteContext())
{
var newScore = new ScoreEntity
{
GameId = 1,
PlayerId = 2,
NbPoints = 5
};
context.Add(newScore);
context.SaveChanges();
}
public class SQLiteContext : TrekContext
@ -35,7 +55,7 @@ public class SQLiteContext : TrekContext
{
if (!options.IsConfigured)
{
options.UseSqlite($"Data Source=projet.Champions.db");
options.UseSqlite($"Data Source=projet.ToutesTables.db");
}
}
}

@ -66,12 +66,12 @@ namespace Trek12_API.Controllers
public async Task<IActionResult> Delete(int idPlayer)
{
var playerToDelete = await playersManager.GetItemsById(idPlayer);
if (playerToDelete == null)
if(playerToDelete == null)
{
return NotFound("Joueur non trouvé");
}
if (!await playersManager.DeleteItem(playerToDelete.SingleOrDefault(p => p.Id == idPlayer)))
if(!await playersManager.DeleteItem(playerToDelete.SingleOrDefault(p => p.Id == idPlayer)))
{
return BadRequest("Erreur lors de la suppression du joueur");
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameWorkLib
{
public class CaseEntity
{
public int CaseId { get; set; }
public int Value { get; set; }
}
}

@ -0,0 +1,22 @@
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 EntityFrameWorkLib
{
public class GameEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int GameId { get; set; }
public TimeSpan Duration { get; set; }
public DateOnly Date { get; set; }
public int NbPlayers { get; set; }
public string Name { get; set; }
//public ICollection<PlayerEntity> NbPoints { get; set; }
}
}

@ -0,0 +1,21 @@
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 EntityFrameWorkLib
{
public class GrilleEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int GrilleId { get; set; }
public int NbChains { get; set; }
public int NbZones { get; set; }
public int MaxChain { get; set; }
public int MaxZone { get; set; }
}
}

@ -1,54 +0,0 @@
// <auto-generated />
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
[DbContext(typeof(TrekContext))]
[Migration("20230212152210_MyMigration")]
partial class MyMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
#pragma warning restore 612, 618
}
}
}

@ -1,39 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
/// <inheritdoc />
public partial class MyMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
NbWin = 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 =>
{
table.PrimaryKey("PK_Players", x => x.PlayerId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Players");
}
}
}

@ -0,0 +1,176 @@
// <auto-generated />
using System;
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
[DbContext(typeof(TrekContext))]
[Migration("20230320170231_AllMigrations")]
partial class AllMigrations
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{
b.Property<int>("CaseId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Value")
.HasColumnType("INTEGER");
b.HasKey("CaseId");
b.ToTable("Case");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.Property<int>("GameId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateOnly>("Date")
.HasColumnType("TEXT");
b.Property<TimeSpan>("Duration")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbPlayers")
.HasColumnType("INTEGER");
b.HasKey("GameId");
b.ToTable("Game");
});
modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b =>
{
b.Property<int>("GrilleId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxChain")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbChains")
.HasColumnType("INTEGER");
b.Property<int>("NbZones")
.HasColumnType("INTEGER");
b.HasKey("GrilleId");
b.ToTable("Grille");
});
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxPoints")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbPlayed")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("NbWin")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("PlayerId");
b.ToTable("Players");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.Property<int>("ScoreId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GameId")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.HasKey("ScoreId");
b.HasIndex("GameId");
b.HasIndex("PlayerId");
b.ToTable("Score");
});
modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b =>
{
b.Property<int>("TurnId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("DiceValue1")
.HasColumnType("INTEGER");
b.Property<int>("DiceValue2")
.HasColumnType("INTEGER");
b.HasKey("TurnId");
b.ToTable("Turn");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.HasOne("EntityFrameWorkLib.GameEntity", "Game")
.WithMany()
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Player");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,151 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFrameWorkLib.Migrations
{
/// <inheritdoc />
public partial class AllMigrations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Case",
columns: table => new
{
CaseId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Value = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Case", x => x.CaseId);
});
migrationBuilder.CreateTable(
name: "Game",
columns: table => new
{
GameId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Duration = table.Column<TimeSpan>(type: "TEXT", nullable: false),
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 =>
{
table.PrimaryKey("PK_Game", x => x.GameId);
});
migrationBuilder.CreateTable(
name: "Grille",
columns: table => new
{
GrilleId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
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 =>
{
table.PrimaryKey("PK_Grille", x => x.GrilleId);
});
migrationBuilder.CreateTable(
name: "Players",
columns: table => new
{
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
NbWin = 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 =>
{
table.PrimaryKey("PK_Players", x => x.PlayerId);
});
migrationBuilder.CreateTable(
name: "Turn",
columns: table => new
{
TurnId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
DiceValue1 = table.Column<int>(type: "INTEGER", nullable: false),
DiceValue2 = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Turn", x => x.TurnId);
});
migrationBuilder.CreateTable(
name: "Score",
columns: table => new
{
ScoreId = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
NbPoints = table.Column<int>(type: "INTEGER", nullable: false),
GameId = table.Column<int>(type: "INTEGER", nullable: false),
PlayerId = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Score", x => x.ScoreId);
table.ForeignKey(
name: "FK_Score_Game_GameId",
column: x => x.GameId,
principalTable: "Game",
principalColumn: "GameId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Score_Players_PlayerId",
column: x => x.PlayerId,
principalTable: "Players",
principalColumn: "PlayerId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Score_GameId",
table: "Score",
column: "GameId");
migrationBuilder.CreateIndex(
name: "IX_Score_PlayerId",
table: "Score",
column: "PlayerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Case");
migrationBuilder.DropTable(
name: "Grille");
migrationBuilder.DropTable(
name: "Score");
migrationBuilder.DropTable(
name: "Turn");
migrationBuilder.DropTable(
name: "Game");
migrationBuilder.DropTable(
name: "Players");
}
}
}

@ -1,4 +1,5 @@
// <auto-generated />
using System;
using EntityFrameWorkLib;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@ -16,6 +17,67 @@ namespace EntityFrameWorkLib.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFrameWorkLib.CaseEntity", b =>
{
b.Property<int>("CaseId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Value")
.HasColumnType("INTEGER");
b.HasKey("CaseId");
b.ToTable("Case");
});
modelBuilder.Entity("EntityFrameWorkLib.GameEntity", b =>
{
b.Property<int>("GameId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateOnly>("Date")
.HasColumnType("TEXT");
b.Property<TimeSpan>("Duration")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbPlayers")
.HasColumnType("INTEGER");
b.HasKey("GameId");
b.ToTable("Game");
});
modelBuilder.Entity("EntityFrameWorkLib.GrilleEntity", b =>
{
b.Property<int>("GrilleId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("MaxChain")
.HasColumnType("INTEGER");
b.Property<int>("MaxZone")
.HasColumnType("INTEGER");
b.Property<int>("NbChains")
.HasColumnType("INTEGER");
b.Property<int>("NbZones")
.HasColumnType("INTEGER");
b.HasKey("GrilleId");
b.ToTable("Grille");
});
modelBuilder.Entity("EntityFrameWorkLib.PlayerEntity", b =>
{
b.Property<int>("PlayerId")
@ -45,6 +107,66 @@ namespace EntityFrameWorkLib.Migrations
b.ToTable("Players");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.Property<int>("ScoreId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("GameId")
.HasColumnType("INTEGER");
b.Property<int>("NbPoints")
.HasColumnType("INTEGER");
b.Property<int>("PlayerId")
.HasColumnType("INTEGER");
b.HasKey("ScoreId");
b.HasIndex("GameId");
b.HasIndex("PlayerId");
b.ToTable("Score");
});
modelBuilder.Entity("EntityFrameWorkLib.TurnEntity", b =>
{
b.Property<int>("TurnId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("DiceValue1")
.HasColumnType("INTEGER");
b.Property<int>("DiceValue2")
.HasColumnType("INTEGER");
b.HasKey("TurnId");
b.ToTable("Turn");
});
modelBuilder.Entity("EntityFrameWorkLib.ScoreEntity", b =>
{
b.HasOne("EntityFrameWorkLib.GameEntity", "Game")
.WithMany()
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("EntityFrameWorkLib.PlayerEntity", "Player")
.WithMany()
.HasForeignKey("PlayerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Game");
b.Navigation("Player");
});
#pragma warning restore 612, 618
}
}

@ -2,17 +2,19 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EntityFrameWorkLib;
public class PlayerEntity
namespace EntityFrameWorkLib
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PlayerId {get; set;}
public string Pseudo { get; set; }
public int NbWin { get; set; }
public int NbPlayed { get; set; }
public int MaxZone { get; set; }
public int MaxPoints { get; set; }
public int NbPoints { get; set; }
public class PlayerEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int PlayerId { get; set; }
public string Pseudo { get; set; }
public int NbWin { get; set; }
public int NbPlayed { get; set; }
public int MaxZone { get; set; }
public int MaxPoints { get; set; }
public int NbPoints { get; set; }
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameWorkLib
{
public class ScoreEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ScoreId { get; set; }
public int NbPoints { get; set; }
public int GameId { get; set; }
[ForeignKey("GameId")]
public GameEntity Game { get; set; }
public int PlayerId { get; set; }
[ForeignKey("PlayerId")]
public PlayerEntity Player { get; set; }
}
}

@ -10,6 +10,16 @@ namespace EntityFrameWorkLib
{
public DbSet<PlayerEntity> Players { get; set; }
public DbSet<GameEntity> Game { get; set; }
public DbSet<GrilleEntity> Grille { get; set; }
public DbSet<CaseEntity> Case { get; set; }
public DbSet<TurnEntity> Turn { get; set; }
public DbSet<ScoreEntity> Score { get; set; }
public TrekContext() { }
public TrekContext(DbContextOptions<TrekContext> options)
: base(options)
@ -18,21 +28,35 @@ namespace EntityFrameWorkLib
{
if (!options.IsConfigured)
{
base.OnConfiguring(options.UseSqlite($"DataSource=projet.Players.db"));
base.OnConfiguring(options.UseSqlite($"DataSource=projet.AllTables.db"));
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//Définition de la clé primaire de PlayerEntity
modelBuilder.Entity<PlayerEntity>().HasKey(n => n.PlayerId);
//Définition de la clé primaire de GameEntity
modelBuilder.Entity<GameEntity>().HasKey(n => n.GameId);
//Définition de la clé primaire de GrilleEntity
modelBuilder.Entity<GrilleEntity>().HasKey(n => n.GrilleId);
//Définition de la clé primaire de CaseEntity
modelBuilder.Entity<CaseEntity>().HasKey(n => n.CaseId);
//Définition de la clé primaire de TurnEntity
modelBuilder.Entity<TurnEntity>().HasKey(n => n.TurnId);
//Définition de la clé primaire de ScoreEntity
modelBuilder.Entity<ScoreEntity>().HasKey(n => n.ScoreId);
//Définition du mode de generation de la clé : génération à l'insertion
modelBuilder.Entity<PlayerEntity>().Property(n => n.PlayerId).ValueGeneratedOnAdd();
modelBuilder.Entity<GameEntity>().Property(n => n.GameId).ValueGeneratedOnAdd();
modelBuilder.Entity<GrilleEntity>().Property(n => n.GrilleId).ValueGeneratedOnAdd();
modelBuilder.Entity<CaseEntity>().Property(n => n.CaseId).ValueGeneratedOnAdd();
modelBuilder.Entity<TurnEntity>().Property(n => n.TurnId).ValueGeneratedOnAdd();
modelBuilder.Entity<ScoreEntity>().Property(n => n.ScoreId).ValueGeneratedOnAdd();
base.OnModelCreating(modelBuilder);
}
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameWorkLib
{
public class TurnEntity
{
public int TurnId { get; set; }
public int DiceValue1 { get; set; }
public int DiceValue2 { get; set; }
}
}
Loading…
Cancel
Save