diff --git a/Sources/BowlingApp/Match.cs b/Sources/BowlingApp/Match.cs index fb074e9..3a17c64 100644 --- a/Sources/BowlingApp/Match.cs +++ b/Sources/BowlingApp/Match.cs @@ -63,17 +63,15 @@ namespace BowlingApp /// public static void JeuIndividuel(Saissiseur saissiseur) { + // Création des parties pour chaque joueur Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager()); - List j2 = (List)manager.GetAllJoueur().Result; - j2.ForEach(joueur => - { - Console.WriteLine(joueur.Pseudo); - }); + Afficheur.InviteNrb("Joueur"); int nbrj = saissiseur.CollecteNbr(); List joueurs = new List(); + // Création des joueurs for (int j = 0; j < nbrj; j++) { @@ -83,8 +81,8 @@ namespace BowlingApp joueurs.Add(joueur); } + - for (int i = 0; i < joueurs.Count; i++) { @@ -130,6 +128,20 @@ namespace BowlingApp manager.AddJoueur(joueur); } + + private static void CreerPatier() + { + /* Afficheur.InviteNom("Joueur"); + string Nom = saissiseur.CollecteNom(); + Joueur joueur = new Joueur(Nom); + Partie partie = new Partie(joueur); + Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager()); + Lancer(partie, saissiseur); + joueur.AddPartie(partie); + //manager.AddPartie(partie); + manager.AddJoueur(joueur);*/ + } + /// /// Faire des lancers /// diff --git a/Sources/BowlingApp/bowling.db b/Sources/BowlingApp/bowling.db index 0f6dee5..2e571a6 100644 Binary files a/Sources/BowlingApp/bowling.db and b/Sources/BowlingApp/bowling.db differ diff --git a/Sources/BowlingEF/Migrations/20221025144845_myMigration.Designer.cs b/Sources/BowlingEF/Migrations/20221025144845_myMigration.Designer.cs new file mode 100644 index 0000000..b6b58a2 --- /dev/null +++ b/Sources/BowlingEF/Migrations/20221025144845_myMigration.Designer.cs @@ -0,0 +1,154 @@ +// +using System; +using BowlingEF.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BowlingEF.Migrations +{ + [DbContext(typeof(BowlingContext))] + [Migration("20221025144845_myMigration")] + partial class myMigration + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("BowlingEF.Entities.EquipeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Nom") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Equipes"); + }); + + modelBuilder.Entity("BowlingEF.Entities.FrameEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Lancer1") + .HasColumnType("INTEGER"); + + b.Property("Lancer2") + .HasColumnType("INTEGER"); + + b.Property("Lancer3") + .HasColumnType("INTEGER"); + + b.Property("Numero") + .HasColumnType("INTEGER"); + + b.Property("PartieId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("PartieId"); + + b.ToTable("Frames"); + }); + + modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EquipeEntityId") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("EquipeEntityId"); + + b.ToTable("Joueurs"); + }); + + modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("JoueurForeignKey") + .HasColumnType("INTEGER"); + + b.Property("Score") + .IsRequired() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("JoueurForeignKey"); + + b.ToTable("Parties"); + }); + + modelBuilder.Entity("BowlingEF.Entities.FrameEntity", b => + { + b.HasOne("BowlingEF.Entities.PartieEntity", "Partie") + .WithMany("Frames") + .HasForeignKey("PartieId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Partie"); + }); + + modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b => + { + b.HasOne("BowlingEF.Entities.EquipeEntity", null) + .WithMany("Joueurs") + .HasForeignKey("EquipeEntityId"); + }); + + modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b => + { + b.HasOne("BowlingEF.Entities.JoueurEntity", "Joueur") + .WithMany("PartieEntities") + .HasForeignKey("JoueurForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Joueur"); + }); + + modelBuilder.Entity("BowlingEF.Entities.EquipeEntity", b => + { + b.Navigation("Joueurs"); + }); + + modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b => + { + b.Navigation("PartieEntities"); + }); + + modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b => + { + b.Navigation("Frames"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/BowlingEF/Migrations/20221025144845_myMigration.cs b/Sources/BowlingEF/Migrations/20221025144845_myMigration.cs new file mode 100644 index 0000000..99c5c03 --- /dev/null +++ b/Sources/BowlingEF/Migrations/20221025144845_myMigration.cs @@ -0,0 +1,119 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BowlingEF.Migrations +{ + public partial class myMigration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Equipes", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Nom = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Equipes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Joueurs", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Pseudo = table.Column(type: "TEXT", nullable: false), + EquipeEntityId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Joueurs", x => x.Id); + table.ForeignKey( + name: "FK_Joueurs_Equipes_EquipeEntityId", + column: x => x.EquipeEntityId, + principalTable: "Equipes", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Parties", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + JoueurForeignKey = table.Column(type: "INTEGER", nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + Score = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Parties", x => x.Id); + table.ForeignKey( + name: "FK_Parties_Joueurs_JoueurForeignKey", + column: x => x.JoueurForeignKey, + principalTable: "Joueurs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Frames", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Numero = table.Column(type: "INTEGER", nullable: false), + Lancer1 = table.Column(type: "INTEGER", nullable: false), + Lancer2 = table.Column(type: "INTEGER", nullable: false), + Lancer3 = table.Column(type: "INTEGER", nullable: false), + PartieId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Frames", x => x.Id); + table.ForeignKey( + name: "FK_Frames_Parties_PartieId", + column: x => x.PartieId, + principalTable: "Parties", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Frames_PartieId", + table: "Frames", + column: "PartieId"); + + migrationBuilder.CreateIndex( + name: "IX_Joueurs_EquipeEntityId", + table: "Joueurs", + column: "EquipeEntityId"); + + migrationBuilder.CreateIndex( + name: "IX_Parties_JoueurForeignKey", + table: "Parties", + column: "JoueurForeignKey"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Frames"); + + migrationBuilder.DropTable( + name: "Parties"); + + migrationBuilder.DropTable( + name: "Joueurs"); + + migrationBuilder.DropTable( + name: "Equipes"); + } + } +} diff --git a/Sources/BowlingEF/Migrations/BowlingContextModelSnapshot.cs b/Sources/BowlingEF/Migrations/BowlingContextModelSnapshot.cs new file mode 100644 index 0000000..b72dd97 --- /dev/null +++ b/Sources/BowlingEF/Migrations/BowlingContextModelSnapshot.cs @@ -0,0 +1,152 @@ +// +using System; +using BowlingEF.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BowlingEF.Migrations +{ + [DbContext(typeof(BowlingContext))] + partial class BowlingContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.10"); + + modelBuilder.Entity("BowlingEF.Entities.EquipeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Nom") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Equipes"); + }); + + modelBuilder.Entity("BowlingEF.Entities.FrameEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Lancer1") + .HasColumnType("INTEGER"); + + b.Property("Lancer2") + .HasColumnType("INTEGER"); + + b.Property("Lancer3") + .HasColumnType("INTEGER"); + + b.Property("Numero") + .HasColumnType("INTEGER"); + + b.Property("PartieId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("PartieId"); + + b.ToTable("Frames"); + }); + + modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("EquipeEntityId") + .HasColumnType("INTEGER"); + + b.Property("Pseudo") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("EquipeEntityId"); + + b.ToTable("Joueurs"); + }); + + modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Date") + .HasColumnType("TEXT"); + + b.Property("JoueurForeignKey") + .HasColumnType("INTEGER"); + + b.Property("Score") + .IsRequired() + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("JoueurForeignKey"); + + b.ToTable("Parties"); + }); + + modelBuilder.Entity("BowlingEF.Entities.FrameEntity", b => + { + b.HasOne("BowlingEF.Entities.PartieEntity", "Partie") + .WithMany("Frames") + .HasForeignKey("PartieId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Partie"); + }); + + modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b => + { + b.HasOne("BowlingEF.Entities.EquipeEntity", null) + .WithMany("Joueurs") + .HasForeignKey("EquipeEntityId"); + }); + + modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b => + { + b.HasOne("BowlingEF.Entities.JoueurEntity", "Joueur") + .WithMany("PartieEntities") + .HasForeignKey("JoueurForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Joueur"); + }); + + modelBuilder.Entity("BowlingEF.Entities.EquipeEntity", b => + { + b.Navigation("Joueurs"); + }); + + modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b => + { + b.Navigation("PartieEntities"); + }); + + modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b => + { + b.Navigation("Frames"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Sources/BowlingEF/bowling.db b/Sources/BowlingEF/bowling.db new file mode 100644 index 0000000..491eddd Binary files /dev/null and b/Sources/BowlingEF/bowling.db differ diff --git a/Sources/BowlingMaping/EquipeDbDataManager.cs b/Sources/BowlingMaping/EquipeDbDataManager.cs index ce00454..94bd663 100644 --- a/Sources/BowlingMaping/EquipeDbDataManager.cs +++ b/Sources/BowlingMaping/EquipeDbDataManager.cs @@ -24,12 +24,22 @@ namespace BowlingMaping { Id = _equipe.Id, Nom = _equipe.Nom, - Joueurs = _equipe.Joueurs.Select(j => new JoueurEntity - { - Id = j.Id, - Pseudo = j.Pseudo - }).ToList() + }; + + for(int i = 0; i<_equipe.Joueurs.Count; i++) + { + JoueurEntity joueur = new JoueurEntity + { + Id = _equipe.Joueurs[i].Id, + Pseudo = _equipe.Joueurs[i].Pseudo, + Equipe = entity + + }; + + entity.Joueurs.Add(joueur); + } + context.Equipes.Add(entity); result = await context.SaveChangesAsync() == 1; }