Mise à jour EF
continuous-integration/drone/push Build is passing Details

Reviewed-on: #69
master
Augustin AFFOGNON 3 years ago
commit b8966afb1c

@ -66,7 +66,7 @@ $ dotnet tool install --global dotnet-ef
* Dans la console, tapez la commande suivante:
```shell
Update-Database
$ dotnet ef database update
```
* L'application est prête à être utilisée.

@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<StartWorkingDirectory >$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>

@ -64,10 +64,14 @@ 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());
Afficheur.InviteNrb("Joueur");
int nbrj = saissiseur.CollecteNbr();
List<Joueur> joueurs = new List<Joueur>();
// Création des joueurs
for (int j = 0; j < nbrj; j++)
{
@ -77,9 +81,8 @@ namespace BowlingApp
joueurs.Add(joueur);
}
// Création des parties pour chaque joueur
Manager manager = new Manager(new EquipeDbDataManager(), new PartieDbDataManager(), new JoueurDbDataManager());
for (int i = 0; i < joueurs.Count; i++)
{
@ -119,16 +122,31 @@ namespace BowlingApp
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);
}
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);
manager.AddPartie(partie);
joueur.AddPartie(partie);
//manager.AddPartie(partie);
manager.AddJoueur(joueur);*/
}
/// <summary>
/// Faire des lancers
/// </summary>
/// <param name="partie"></param>
/// <param name="saissiseur"></param>
/// <param name="saissiseur"></param"""
private static void Lancer(Partie partie,Saissiseur saissiseur)
{
for (int i = 0; i < 10; i++)
@ -136,10 +154,21 @@ namespace BowlingApp
Afficheur.AfficheNumFrame(i + 1);
Frame frame = new Frame(i + 1);
Afficheur.InviteQuilleTombe(1);
frame.Lancer1 = new Lancer(saissiseur.CollectQuilleTomber());
Afficheur.InviteQuilleTombe(2);
frame.Lancer2 = new Lancer(saissiseur.CollectQuilleTomber());
frame.Lancer(saissiseur.CollectQuilleTomber());
if (!frame.IsStrike)
{
Afficheur.InviteQuilleTombe(2);
frame.Lancer(saissiseur.CollectQuilleTomber());
}
if (i==9)
{
Frame frame1 = new Frame(i + 2);
Afficheur.InviteQuilleTombe(3);
frame.Lancer(saissiseur.CollectQuilleTomber());
}
partie.AddFrame(frame);
Console.WriteLine(partie.GetScore());
}
}
#endregion

Binary file not shown.

@ -20,7 +20,7 @@ namespace BowlingEF.Context
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Data Source=C:\\Users\\DELL\\BowlingScoreApp\\Sources\\BowlingApp\\bowling.db");
optionsBuilder.UseSqlite("Data Source=bowling.db");
}
}

@ -19,14 +19,7 @@ namespace BowlingEF.Entities
[Required]
public int Lancer2 { get; set; }
public int Lancer3 { get; set; }
[Required]
public bool IsStrike { get; set; }
[Required]
public bool IsSpare { get; set; }
[ForeignKey("PartieId")]
[Required]
public long PartieId { get; set; }
public PartieEntity Partie { get; set; }
#endregion
}

@ -15,6 +15,7 @@ namespace BowlingEF.Entities
[Required]
public string Pseudo { get; set; }
public ICollection<PartieEntity> PartieEntities { get; set; } = new List<PartieEntity>();
#endregion
}
}

@ -17,11 +17,9 @@ namespace BowlingEF.Entities
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
public JoueurEntity Joueur { get; set; }
[ForeignKey("JoueurId")]
[Required]
public long JoueurId { get; set; }
[ForeignKey("JoueurForeignKey")]
public JoueurEntity Joueur { get; set; }
[Required]
public DateTime Date { get; set; }
public ICollection<FrameEntity> Frames { get; set; }

@ -0,0 +1,154 @@
// <auto-generated />
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<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Nom")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Equipes");
});
modelBuilder.Entity("BowlingEF.Entities.FrameEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Lancer1")
.HasColumnType("INTEGER");
b.Property<int>("Lancer2")
.HasColumnType("INTEGER");
b.Property<int>("Lancer3")
.HasColumnType("INTEGER");
b.Property<int>("Numero")
.HasColumnType("INTEGER");
b.Property<long>("PartieId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PartieId");
b.ToTable("Frames");
});
modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long?>("EquipeEntityId")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("EquipeEntityId");
b.ToTable("Joueurs");
});
modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<long>("JoueurForeignKey")
.HasColumnType("INTEGER");
b.Property<int?>("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
}
}
}

@ -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<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Nom = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Equipes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Joueurs",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column<string>(type: "TEXT", nullable: false),
EquipeEntityId = table.Column<long>(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<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
JoueurForeignKey = table.Column<long>(type: "INTEGER", nullable: false),
Date = table.Column<DateTime>(type: "TEXT", nullable: false),
Score = table.Column<int>(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<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Numero = table.Column<int>(type: "INTEGER", nullable: false),
Lancer1 = table.Column<int>(type: "INTEGER", nullable: false),
Lancer2 = table.Column<int>(type: "INTEGER", nullable: false),
Lancer3 = table.Column<int>(type: "INTEGER", nullable: false),
PartieId = table.Column<long>(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");
}
}
}

@ -0,0 +1,152 @@
// <auto-generated />
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<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Nom")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Equipes");
});
modelBuilder.Entity("BowlingEF.Entities.FrameEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Lancer1")
.HasColumnType("INTEGER");
b.Property<int>("Lancer2")
.HasColumnType("INTEGER");
b.Property<int>("Lancer3")
.HasColumnType("INTEGER");
b.Property<int>("Numero")
.HasColumnType("INTEGER");
b.Property<long>("PartieId")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PartieId");
b.ToTable("Frames");
});
modelBuilder.Entity("BowlingEF.Entities.JoueurEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long?>("EquipeEntityId")
.HasColumnType("INTEGER");
b.Property<string>("Pseudo")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("EquipeEntityId");
b.ToTable("Joueurs");
});
modelBuilder.Entity("BowlingEF.Entities.PartieEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("Date")
.HasColumnType("TEXT");
b.Property<long>("JoueurForeignKey")
.HasColumnType("INTEGER");
b.Property<int?>("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
}
}
}

Binary file not shown.

@ -149,7 +149,7 @@ namespace BowlingLib.Model
/// <param name="lancer1"></param>
/// <param name="lancer2"></param>
/// <param name="lancer3"></param>
public Frame(long id, int numero, int lancer1, int lancer2, [AllowNull] int lancer3) : this(numero)
public Frame(long id, int numero, int lancer1, int lancer2, int lancer3) : this(numero)
{
this.id = id;
Lancer1 = new Lancer(lancer1);

@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace BowlingLib.Model
{
/// <summary>
@ -14,12 +16,16 @@ namespace BowlingLib.Model
#region Propriétés
private string pseudo;
private readonly long id;
private readonly List<Partie> parties=new();
public ReadOnlyCollection<Partie> Parties { get; }
#endregion
#region Constructeurs
public Joueur(string pseudo)
{
this.Pseudo = pseudo;
Parties = new ReadOnlyCollection<Partie>(parties);
}
public Joueur(long id, string pseudo) : this(pseudo)
@ -76,6 +82,11 @@ namespace BowlingLib.Model
return Pseudo.GetHashCode();
}
public void AddPartie(Partie p)
{
parties.Add(p);
}
#endregion
}
}

@ -46,7 +46,7 @@ namespace BowlingLib.Model
public Partie(Joueur joueur)
{
this.Joueur = joueur;
Date = DateTime.Now;
Frames = new ReadOnlyCollection<Frame>(frames);
}
@ -77,6 +77,7 @@ namespace BowlingLib.Model
/// <returns>le Score d'une partie</returns>
public int? GetScore()
{
score = 0;
for (int i = 0; i < Frames.Count; i++)
{
score += Frames[i].QuillesTombees;

@ -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;
}

@ -3,8 +3,10 @@ using BowlingEF.Entities;
using BowlingLib.Model;
using Business;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -27,13 +29,51 @@ namespace BowlingMaping
bool result = false;
using (var context = new BowlingContext())
{
JoueurEntity entity=new JoueurEntity
try
{
Id = _joueur.Id,
Pseudo = _joueur.Pseudo,
};
context.Joueurs.Add(entity);
result =await context.SaveChangesAsync() == 1;
//Mapping entre la classe joueur et la classe joueurEntity
JoueurEntity entity = new JoueurEntity
{
Id = _joueur.Id,
Pseudo = _joueur.Pseudo,
};
//Parcourt de la liste des parties d'un joueur
for (int i = 0; i < _joueur.Parties.Count; i++)
{
//Mapping entre les parties d'un joueur et les partieEntity d'une partieEntity
PartieEntity partieEntity = new PartieEntity
{
Joueur = entity,
Date = _joueur.Parties[i].Date,
Score = _joueur.Parties[i].Score
};
//Parcourt de la liste des frames d'une partie
for (int j = 0; j < _joueur.Parties[i].Frames.Count; j++)
{
//Mapping entre les frames d'une partie et les frameEntity d'une partieEntity
FrameEntity frameEntity = new FrameEntity
{
Id = _joueur.Parties[i].Frames[j].Id,
Lancer1 = _joueur.Parties[i].Frames[j].Lancer1.QuillesTombees,
Lancer2 = _joueur.Parties[i].Frames[j].Lancer2.QuillesTombees,
Lancer3 = (_joueur.Parties[i].Frames[j].Lancer3 == null) ? 0 : _joueur.Parties[i].Frames[j].Lancer3.QuillesTombees,//si Lancer3 est null il prend la valeur Zero
Partie = partieEntity
};
partieEntity.Frames.Add(frameEntity);
}
entity.PartieEntities.Add(partieEntity);
}
context.Joueurs.Add(entity);
result = await context.SaveChangesAsync() == 1;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
throw;
}
}
return result;
}

@ -31,12 +31,21 @@ namespace BowlingMaping
{
Id = _partie.Id,
Date = _partie.Date,
JoueurId = _partie.Joueur.Id,
Score = _partie.Score
};
context.Parties.Add(entity);
result = await context.SaveChangesAsync() == 1;
try
{
var data = await context.SaveChangesAsync();
result = data == 1;
}
catch (Exception ex)
{
Console.WriteLine(ex);
throw;
}
}
return result;
}
@ -69,7 +78,7 @@ namespace BowlingMaping
{
PartieEntity entity = context.Parties.Find(_partie.Id);
entity.Date = _partie.Date;
entity.JoueurId = _partie.Joueur.Id;
//entity.JoueurId = _partie.Joueur.Id;
entity.Score = _partie.Score;
result =await context.SaveChangesAsync() == 1;
}

Loading…
Cancel
Save